public class Solution
{
public void GameOfLife(int[][] board)
{
var row = board.GetLength() - ;
var col = board[].GetLength() - ;
var list = new List<List<int>>();
for (int r = ; r <= row; r++)
{
var l = new List<int>();
for (int c = ; c <= col; c++)
{
l.Add(board[r][c]);
}
list.Add(l);
} for (int r = ; r <= row; r++)
{
for (int c = ; c <= col; c++)
{
int livecount = ;
for (int i = -; i <= ; i++)
{
for (int j = -; j <= ; j++)
{
if (i == && j == )
{
continue;
}
var newx = r + i;
var newy = c + j;
if (newx < || newx > row || newy < || newy > col)
{
continue;
}
if (board[newx][newy] == )
{
livecount++;//活节点
}
}
}
if (board[r][c] == )//当前节点是活节点
{
if (livecount == || livecount == )
{
list[r][c] = ;
}
else
{
list[r][c] = ;
}
}
else
{
if (livecount == )
{
list[r][c] = ;
}
}
}
} for (int i = ; i < list.Count; i++)
{
for (int j = ; j < list[].Count; j++)
{
board[i][j] = list[i][j];
}
}
}
}

leetcode289的更多相关文章

  1. [Swift]LeetCode289. 生命游戏 | Game of Life

    According to the Wikipedia's article: "The Game of Life, also known simply as Life, is a cellul ...

  2. 2017-3-9 leetcode 283 287 289

    今天操作系统课,没能安心睡懒觉23333,妹抖龙更新,可惜感觉水分不少....怀念追RE0的感觉 =================================================== ...

随机推荐

  1. web端高德地图javascript API的调用

    [转载https://www.cnblogs.com/zimuzimu/p/6202244.html]web端高德地图javascript API的调用 关于第三放地图的使用,腾讯.百度.高德 具体怎 ...

  2. 每天一个linux命令(文件上传下载文件操作):【转载】gzip命令

    减少文件大小有两个明显的好处,一是可以减少存储空间,二是通过网络传输文件时,可以减少传输的时间.gzip是在Linux系统中经常使用的一个对文件进行压缩和解压缩的命令,既方便又好用.gzip不仅可以用 ...

  3. 每天一个linux命令:【转载】ls命令

    ls命令是linux下最常用的命令.ls命令就是list的缩写,缺省下ls用来打印出当前目录的清单,如果ls指定其他目录,那么就会显示指定目录里的文件及文件夹清单. 通过ls 命令不仅可以查看linu ...

  4. BZOJ3932 CQOI2015 任务查询系统 【主席树】

    BZOJ3932 CQOI2015 任务查询系统 Description 最近实验室正在为其管理的超级计算机编制一套任务管理系统,而你被安排完成其中的查询部分.超级计算机中的任务用三元组(Si,Ei, ...

  5. python动态给对象或者类添加方法

    参考:http://stackoverflow.com/questions/972/adding-a-method-to-an-existing-object In Python, there is ...

  6. Discuz! X2.5RC 全新安装图文教程

    http://www.discuz.net/thread-2660015-1-1.html 一步步教你利用Discuz X2.5建设论坛视频教程(174集) http://down.51cto.com ...

  7. springboot: 使web项目支持jsp

    1.springboot为什么不推荐使用jsp? 参考地址:https://spring.io/blog/2012/10/30/spring-mvc-from-jsp-and-tiles-to-thy ...

  8. SVN checkout 出的项目在PHPstorm中打开没有subversion(SVN)选项按钮怎么办?

    对于svn add 命令的批量操作,为了操作简便还是习惯在IDE中完成,有时候新checkout出的项目,在PHPstorm中右键菜单中没有 Subversion 按钮,操作如下: 点击VCS按钮,然 ...

  9. elasticsearch 6.0.0及之后移除了一个索引允许映射多个类型的操作(Removal of mapping types)

    分给线一下内容为理解错误内容,实际允许建立父子分档,只是类型改成来 join 官方demo: join datatypeedit The join datatype is a special fiel ...

  10. 使用zabbix监控mysql

    系统版本: centos6 x86_64 mysql版本: mysql5.6 实施目的: 监控mysql 客户端配置: 1.准备工作:搭建zabbix服务,使服务端客户端连接成功,并有基础监控项 2. ...