leetcode289
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的更多相关文章
- [Swift]LeetCode289. 生命游戏 | Game of Life
According to the Wikipedia's article: "The Game of Life, also known simply as Life, is a cellul ...
- 2017-3-9 leetcode 283 287 289
今天操作系统课,没能安心睡懒觉23333,妹抖龙更新,可惜感觉水分不少....怀念追RE0的感觉 =================================================== ...
随机推荐
- BZOJ2303: [Apio2011]方格染色 【并查集】
Description Sam和他的妹妹Sara有一个包含n × m个方格的表格.她们想要将其的每个方格都染成红色或蓝色.出于个人喜好,他们想要表格中每个2 × 2的方形区域都包含奇数个(1 个或 3 ...
- 《DSP using MATLAB》示例Example 6.8
今天情人节,又在外地出差,苦逼中…… 继续写读书笔记吧. 代码: % All-Zeros FIR filter to Lattice structure filter b = [2, 13/12, 5 ...
- springMVC+Mybatis的maven-web项目的pom.xml文件内容
pom.xml文件内容 <!-- 第一行是XML头,指定了该xml文档的版本和编码方式 --> <project xmlns="http://maven.apache.or ...
- 在linux修改文件夹及其子文件夹的权限。
加入-R 参数,就可以将读写权限传递给子文件夹例如chmod -R 777 /home/mypackage那么mypackage 文件夹和它下面的所有子文件夹的属性都变成了777.777是读.写.执行 ...
- docker 镜像导入导出[转]
0)查看镜像id sudo docker images REPOSITORY TAG IMAGE ID CREATED SIZE quay.io/calico/node v1.0.1 c70511a4 ...
- Oracle 之 AIO (异步io)
Linux 异步 I/O (AIO)是 Linux 内核中提供的一个增强的功能.它是Linux 2.6 版本内核的一个标准特性,AIO 背后的基本思想是允许进程发起很多 I/O 操作,而不用阻塞或等 ...
- yum方式安装的Apache目录详解和配置说明
在对httpd.conf文件进行解读之前,首先了解一下Redhat9中Apache服务器默认配置的一些基本信息:配置文件:/etc/httpd/conf/http.conf1)"/etc/h ...
- SecureCRT导入已有会话
如果别人有完整的环境信息,我们想拿过来,怎么导入?或者别人想要我的会话配置信息,怎么导出?对SecureCRT这个工具来说很easy,根本不需要去找什么导入.导出按钮,直接文件操作. 假如我的Secu ...
- mysql binlog_format row and Statement 比较
两种模式的对比: Statement 优点 历史悠久,技术成熟: 产生的 binlog 文件较小: binlog 中包含了所有数据库修改信息,可以据此来审核数据库的安全等情况: binlog 可以用于 ...
- Python库-BeautifulSoup
sp = BeautifulSoup.bs4.BeautifulSoup(html.text,"html.parser") 方法 1.sp.title 返回网页标题 2.sp.te ...