[Leetcode每日一题]289. 生命游戏

2025年北京市职工职业技能大赛第六届信息通信行业网络安全技能大赛复赛CTF部分WP-哥斯拉流量分析 题目没有任何提示,附件gzl.pcap解题哥斯拉流量300多KB包很多,没啥经验只能挨个看回来之后又狠狠得撸了一把哥斯拉流量分析我这里用的是哥斯拉4.0.1测试链接这里发了两个包,我们进行分析。 阅读详情

题目描述:

根据 百度百科 , 生命游戏 ,简称为 生命 ,是英国数学家约翰·何顿·康威在 1970 年发明的细胞自动机。

给定一个包含 m × n 个格子的面板,每一个格子都可以看成是一个细胞。每个细胞都具有一个初始状态: 1 即为 活细胞 (live),或 0 即为 死细胞 (dead)。每个细胞与其八个相邻位置(水平,垂直,对角线)的细胞都遵循以下四条生存定律:

如果活细胞周围八个位置的活细胞数少于两个,则该位置活细胞死亡;
如果活细胞周围八个位置有两个或三个活细胞,则该位置活细胞仍然存活;
如果活细胞周围八个位置有超过三个活细胞,则该位置活细胞死亡;
如果死细胞周围正好有三个活细胞,则该位置死细胞复活;

下一个状态是通过将上述规则同时应用于当前状态下的每个细胞所形成的,其中细胞的出生和死亡是同时发生的。给你 m x n 网格面板 board 的当前状态,返回下一个状态。

示例 1:
在这里插入图片描述
输入:board = [[0,1,0],[0,0,1],[1,1,1],[0,0,0]]
输出:[[0,0,0],[1,0,1],[0,1,1],[0,1,0]]

示例 2:
在这里插入图片描述

输入:board = [[1,1],[1,0]]
输出:[[1,1],[1,1]]

提示:
m = board.length
n = board[i].length
1 <= m, n <= 25
board[i][j] 为 0 或 1

代码:

package leetcodeday1;

public class leetcode289 {

    // 八个方向
    int[] dx = {-1, 1, 0, 0, -1, -1, 1, 1};
    int[] dy = {0, 0, -1, 1, -1, 1, -1, 1};

    // 枚举,扫描该细胞八个方向上细胞的情况,并以此进行操作,即边扫描边改变当前细胞的状态
    // 但这样会存在问题,你改变了某个点的状态,之后的细胞也会受到影响
//    public void gameOfLife(int[][] board) {
//        if (board.length == 0){
//            return;
//        }
//        int m = board.length;
//        int n = board[0].length;
//
//        // 标记数组,0为不变,1代表变成活细胞, 0代表变成死细胞
//        int[][] flag = new int[m][n];
//        for (int i = 0; i < m; i++){
//            for (int j = 0; j < n; j++){
//                flag[i][j] = 0;
//            }
//        }
//
//        for (int i = 0; i < m; i++){
//            for (int j = 0; j < n; j++){
//                //记录该细胞八个方向的活细胞数量
//                int cnt = 0;
//                for (int k = 0; k < 8; k++){
//                    int x = i + dx[k];
//                    int y = j + dy[k];
//                    if (x < 0 || x >= m || y < 0 || y >= n){
//                        continue;
//                    }
//                    cnt += (board[x][y] & 1);
//                }
//                // 该细胞为活细胞
//                if ((board[i][j] & 1) == 1){
//                    // 情况1
//                    if (cnt < 2){
//                        flag[i][j] = -1;
//                    }
//                    else if (cnt <=3){
//                        // 情况2
//                        flag[i][j] = 1;
//                    }else {
//                        // 情况3
//                        flag[i][j] = -1;
//                    }
//                }else {
//                    //该细胞为死细胞
//                    // 情况4
//                    if (cnt == 3){
//                        flag[i][j] = 1;
//                    }
//
//                }
//            }
//        }
//        for (int i = 0 ; i < m; i++){
//            for (int j = 0; j < n; j++){
//                if (flag[i][j] == 1){
//                    board[i][j] = 1;
//                }
//                if (flag[i][j] == -1){
//                    board[i][j] = 0;
//                }
//            }
//        }
//        for (int i = 0 ; i < m; i++){
//            for (int j = 0; j < n; j++){
//                System.out.print(board[i][j] + " ");
//            }
//            System.out.println();
//        }
//    }
    public void gameOfLife(int[][] board) {
        if (board.length == 0){
            return;
        }
        int m = board.length;
        int n = board[0].length;

        // 存储中间变化
        int[][] flag = new int[m][n];
        for (int i = 0; i < m; i++){
            for (int j = 0; j < n; j++){
                flag[i][j] = board[i][j];
            }
        }

        for (int i = 0; i < m; i++){
            for (int j = 0; j < n; j++){
                //记录该细胞八个方向的活细胞数量
                int cnt = 0;
                for (int k = 0; k < 8; k++){
                    int x = i + dx[k];
                    int y = j + dy[k];
                    if (x < 0 || x >= m || y < 0 || y >= n){
                        continue;
                    }
                    cnt += (board[x][y] & 1);
                }
                // 该细胞为活细胞
                if ((board[i][j] & 1) == 1){
                    // 情况1
                    if (cnt < 2){
                        flag[i][j] = 0;
                    }
                    else if (cnt <=3){
                        // 情况2
                        flag[i][j] = 1;
                    }else {
                        // 情况3
                        flag[i][j] = 0;
                    }
                }else {
                    //该细胞为死细胞
                    // 情况4
                    if (cnt == 3){
                        flag[i][j] = 1;
                    }

                }
            }
        }

        //  统一进行改变
        for (int i = 0 ; i < m; i++){
            for (int j = 0; j < n; j++){
                board[i][j] = flag[i][j];
            }
        }

    }

    public static void main(String[] args) {
        leetcode289 obj = new leetcode289();
        int[][] board = {
                {0,1,0},{0,0,1},{1,1,1},{0,0,0}
        };
        obj.gameOfLife(board);
    }

}

目标检测数据集 第069期-基于yolo标注格式的玻璃清洁状态检测数据集(含免费分享) 但这类技术的落地,离不开大量标注规范、场景丰富的数据集作为算法训练的支撑,玻璃清洁状态检测数据集的出现,正是为了满足这一市场与技术需求。在高校与科研机构的计算机视觉研究中,该数据集可作为基础研究素材,用于探索物体状态识别的算法优化方向,比如针对玻璃这类透明物体的检测算法改进,或是小样本场景下的状态识别研究。通过摄像头采集车窗、挡风玻璃的图像,算法自动检测玻璃清洁度,若识别到脏污影响视线,及时提醒运维人员清洁,避免因玻璃脏污引发的安全事故,提升交通出行的安全性。 阅读详情

相关推荐

python音频信号分析

声音以具有诸如频率、带宽、分贝等参数的音频信号的形式表示,典型的音频信号可以表示为幅度和时间的函数

MAY的博客 2798

289. 生命游戏

lc 289

duoyasong5907的博客 813

别再到处找资源了!WinCC 7.5 SP2官方下载与Windows 10保姆级安装避坑指南

本文提供了WinCC 7.5 SP2在Windows 10上的官方下载与安装全流程指南,重点解决了资源获取难、系统兼容性问题及分卷压缩处理等常见痛点。通过详细的步骤和实用技巧,帮助用户顺利完成安装并优化配置,适用于工控领域的学习者和从业者。

weixin_32924297的博客 537

LeetCode-289-生命游戏

我们可以按照要求,直接在矩阵进行原地修改。但是我们进行原地修改时需要考虑修改后的元素对后续的判断产生影响。因此我们可以使用中间状态-1和2来代表现有活细胞即将死亡和死亡细胞准备复活的两种特殊状态。并在最终遍历整个矩阵,将特殊状态修改为新时刻下的状态。

L.Wzz的博客 229

macOS 发票查验全攻略:从证书导入到Safari调试

本文详细介绍了在macOS上进行发票查验的全流程,包括证书下载、钥匙串访问导入、Safari浏览器调试等关键步骤。重点解决了验证码不显示等常见问题,提供了证书信任设置和开发者工具使用的实用技巧,帮助用户顺利完成税务发票在线查验。

weixin_29204749的博客 550

【零基础学习CAPL】——弹窗信息提示

不用手动制作Panel窗口,直接使用CAPL脚本实现弹窗提示。//没有wait超时,等待测试人员确认//有wait超时,对话框在超时后自动终止//有wait超时,可以显示一个资源,即对话框可以显示额外的信息。/*参数说明text:显示在弹窗中的内容,长度限制在4096字符timeout:弹窗自动结束的时间,单位:ms。若为0,则无超时控制heading:对话框文本上方的标题。字符串最大长度限制在256个字符。resource:URL或文件路径。字符串的最大长度是有限的(512个字符)。

LOVE135149的博客 278

leetcode289.生命游戏

根据 百度百科 , 生命游戏 ,简称为 生命 ,是英国数学家约翰·何顿·康威在 1970 年发明的细胞自动机。给定一个包含 m × n 个格子的面板,每一个格子都可以看成是一个细胞。每个细胞都具有一个初始状态: 1 即为 活细胞 (live),或 0 即为 死细胞 (dead)。每个细胞与其八个相邻位置(水平,垂直,对角线)的细胞都遵循以下四条生存定律:如果活细胞周围八个位置的活细胞数少于两个,则该位置活细胞死亡;如果活细胞周围八个位置有两个或三个活细胞,则该位置活细胞仍然存活;

m0_48723204的博客 415

2022中山大学计算机技术专硕考研初试、复试经验帖

个人简介 推荐几个我自己感觉对考研非常有帮助的小助手吧。可以帮助节省时间! 考研时间规划总览 初试篇 数学 英语 政治 408 复试篇 机试 笔试 面试 关于选导师 个人感言

zik的博客 1万+

(矩阵) 289. 生命游戏 ——【Leetcode每日一题】

难度:中等根据 百度百科 , 生命游戏 ,简称为 生命 ,是英国数学家约翰·何顿·康威在 1970 年发明的细胞自动机。给定一个包含 个格子的面板,每一个格子都可以看成是一个细胞。每个细胞都具有一个初始状态: 即为 活细胞 (live),或 即为 死细胞 (dead)。每个细胞与其八个相邻位置(水平,垂直,对角线)的细胞都遵循以下四条生存定律:下一个状态是通过将上述规则同时应用于当前状态下的每个细胞所形成的,其中细胞的出生和死亡是同时发生的。给你 网格面板 的当前状态,返回下一个状态。提示:进阶:

weixin_43412762的博客 1391

使用ESP32设计嵌入式蓝牙游戏手柄

通过使用ESP32开发板和相关的库,我们可以设计和实现嵌入式蓝牙游戏手柄。连接到该设备后,您可以使用控制器模块的按钮和摇杆等元件来模拟游戏手柄的输入。根据您使用的具体模块和引脚分配,连接按钮和摇杆等控制元件到ESP32的GPIO引脚。ESP32是一款功能强大的微控制器,集成了Wi-Fi和蓝牙功能,非常适合用于开发物联网和嵌入式应用。请注意,本文仅提供了一个基于ESP32的嵌入式蓝牙游戏手柄设计示例,具体实现可能因硬件和需求而有所不同。确保开发板正确连接到计算机,并选择正确的开发板和端口。

CodeMaven的博客 1645

模型可解释性分析:基于SHAP的深度探索

SHAP模型可解释性分析摘要 本文系统性地介绍了SHAP(SHapley Additive exPlanations)方法在机器学习模型可解释性分析中的应用。SHAP基于博弈论的Shapley值理论,为特征重要性评估提供了统一框架。文章详细阐述了四种核心算法:Kernel SHAP(模型无关方法)、Tree SHAP(针对树模型的高效算法)、Deep SHAP(适用于深度学习)和Linear SHAP(线性模型专用)。通过Python实现展示了从数据准备到SHAP分析的全流程,包括摘要图、依赖图等可视化技术

huanghm88的专栏 630

LeetCode高频面试60天打卡日记Day33(生命游戏)

Day33() idea: 不能每个点周围判断完之后立即更新周围点的状态,因为当前点的周围状态会是下一次研究的中心点对象,采取标志位方式 2代表:alive–>dead -1: dead–>alive class Solution { public int m; public int n; public void gameOfLife(int[][] b...

YoungNUAA的博客 214

4、双足机器人mpc基础概念

机器人控制实际上不是连续的,是离散的,这就是控制信号的采样周期dt,一般每1ms对机器人发起一次控制信号。一般来说,dt越小,控制器的响应速度越快,但是由于预测的精度有限,如果控制时域过长,预测的误差会逐渐累积,导致控制器的性能下降。注意:1)在程序处理时,u的维度并不是由机器人的自由度确定的,是由其变量的个数及每个变量的空间维度确定,对于双足,采用力矩和力来控制,则u的维度是“2*2*3=12”。机器人实际运动过程中表现出来的状态x,x和xd是一致的,也包括运动速度ν、角速度ω、角度θ、位置p等。

1220

LeetCode 每日一题 289. 生命游戏 详细题解 C++描述

LeetCode 每日一题 289. 生命游戏 2020.04.02 难度 中等 题目 根据 百度百科 ,生命游戏,简称为生命,是英国数学家约翰·何顿·康威在 1970 年发明的细胞自动机。 给定一个包含 m × n 个格子的面板,每一个格子都可以看成是一个细胞。每个细胞都具有一个初始状态:1 即为活细胞(live),或 0 即为死细胞(dead)。每个细胞与其八个相邻位置(水平,垂直,对角线)的...

一起加油 7242

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

【每日一题-leetcode】289. 生命游戏

289. 生命游戏 生命游戏 难度中等234 根据 百度百科 ,生命游戏,简称为生命,是英国数学家约翰·何顿·康威在 1970 年发明的细胞自动机。 给定一个包含 m × n 个格子的面板,每一个格子都可以看成是一个细胞。每个细胞都具有一个初始状态:1 即为活细胞(live),或 0 即为死细胞(dead)。每个细胞与其八个相邻位置(水平,垂直,对角线)的细胞都遵循以下四条生存定律: 如果活细胞周围八个位置的活细胞数少于两个,则该位置活细胞死亡; 如果活细胞周围八个位置有两个或三个活细胞,则该位置活

芝兰生于深谷,不以无人而不芳 692

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

【Java】力扣_每日一题_289.生命游戏_中等

题目链接:https://leetcode-cn.com/problems/game-of-life/ 题目描述 根据 百度百科 ,生命游戏,简称为生命,是英国数学家约翰·何顿·康威在 1970 年发明的细胞自动机。 给定一个包含 m × n 个格子的面板,每一个格子都可以看成是一个细胞。每个细胞都具有一个初始状态:1 即为活细胞(live),或 0 即为死细胞(dead)。每个细胞与其八个相邻位...

includei的博客 382

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

Java每日一题:LeetCode-289. 生命游戏

这是我做过的一个题,我把它分享给你们: 这是原文链接:https://leetcode-cn.com/problems/plus-one/ 如果感觉我做的还行的话,记得点赞。

xweiwxh的博客 328

【LeetCode】 289. Game of Life 生命游戏(Medium)(JAVA)每日一题

【LeetCode】 289. Game of Life 生命游戏(Medium)(JAVA) 题目地址: https://leetcode.com/problems/game-of-life/ 题目描述: According to the Wikipedia’s article: “The Game of Life, also known simply as Life, is a cellula...

qq_16927853的博客 266

[LeetCode每日1题][中等] 289. 生命游戏

文章目录题目模拟法(原地) 题目 289. 生命游戏 - 力扣(LeetCode) 模拟法(原地) 普通解法没什么难度,需要另开一个数组,O(mn)空间复杂度。原地算法:把之前死的后来活的,和之前活的后来死的标记一下,最后再处理一下即可。 class Solution { public: void gameOfLife(vector<vector<int>> &...

EvergIow的博客 303

Leetcode—289. 生命游戏【中等】

Leetcode—289. 生命游戏【中等】

Atticus的博客 918

每日两题leetcode - 136.只出现一次的数字 & 289.生命游戏

java script版 - 每日两题leetcode - 136.只出现一次的数字 & 289.生命游戏

cjn1997的博客 206

每日算法系列【LeetCode 289】生命游戏

题目描述 根据百度百科,生命游戏,简称为生命,是英国数学家约翰·何顿·康威在1970年发明的细胞自动机。 给定一个包含 m × n 个格子的面板,每一个格子都可以看成是一个细胞。每个细胞具有一个初始状态 live(1)即为活细胞, 或 dead(0)即为死细胞。每个细胞与其八个相邻位置(水平,垂直,对角线)的细胞都遵循以下四条生存定律: ...

算法码上来 460

LeetCode-289. 生命游戏

生命游戏 根据 百度百科 ,生命游戏,简称为生命,是英国数学家约翰·何顿·康威在 1970 年发明的细胞自动机。 给定一个包含 m × n 个格子的面板,每一个格子都可以看成是一个细胞。每个细胞都具有一个初始状态:1 即为活细胞(live),或 0 即为死细胞(dead)。每个细胞与其八个相邻位置(水平,垂直,对角线)的细胞都遵循以下四条生存定律: 如果活细胞周围八个位置的活细胞数少于两个,则该位...

奥利波德的魔法屋 189

[每日一题] 159. 生命游戏(编码、常规解法)

文章目录1. 题目来源2. 题目说明3. 题目解析方法一:编码+常规解法 1. 题目来源 链接:289. 生命游戏 来源:LeetCode 2. 题目说明 3. 题目解析 方法一:编码+常规解法 由于题目中要求用原地算法来解题,所以就不能新建一个相同大小的数组,那么只能更新原有数组。题目中要求所有的位置必须被同时更新,但在循环程序中还是一个位置一个位置更新的,当一个位置更新了,这个位置成为其他...

Y-puyu 的博客 526

你不得不看的leetcode常考题(四月份每日一题)——Python版本

四月的每日一题 1号——1111. 有效括号的嵌套深度相关题目:20. 有效的括号2号——289. 生命游戏3号——8. 字符串转换整数 (atoi)4号——42. 接雨水5号——460. LFU缓存6号——72. 编辑距离7号——面试题 01.07. 旋转矩阵8号——面试题13. 机器人的运动范围9号——22. 括号生成学习内容:回溯算法10号——151. 翻转字符串里的单词11号——887. 鸡蛋掉落12号——面试题 16.03. 交点13号——355. 设计推特14号——445. 两数相加 II..

chuxuezheerer的博客 675

【leetcode】【medium】【每日一题】289. Game of Life​​​​​​​

289. Game of Life According to theWikipedia's article: "TheGame of Life, also known simply asLife, is a cellular automaton devised by the British mathematician John Horton Conway in 1970." Given ...

lemonade13的博客 114
上一篇: [Leetcode每日一题]357. 统计各位数字都不同的数字个数
下一篇: [Leetcode每日一题]806. 写字符串需要的行数
Puppet__
博客等级 码龄10年 319粉丝 328原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值