529 Minesweeper 扫雷游戏
2024-09-30 09:08:59
详见:https://leetcode.com/problems/minesweeper/description/
C++:
class Solution {
public:
vector<vector<char>> updateBoard(vector<vector<char>>& board, vector<int>& click)
{
if (board.empty() || board[0].empty())
{
return {};
}
int m = board.size(), n = board[0].size(), row = click[0], col = click[1], cnt = 0;
if (board[row][col] == 'M')
{
board[row][col] = 'X';
}
else
{
for (int i = -1; i < 2; ++i)
{
for (int j = -1; j < 2; ++j)
{
int x = row + i, y = col + j;
if (x < 0 || x >= m || y < 0 || y >= n)
{
continue;
}
if (board[x][y] == 'M')
{
++cnt;
}
}
}
if (cnt > 0)
{
board[row][col] = cnt + '0';
}
else
{
board[row][col] = 'B';
for (int i = -1; i < 2; ++i)
{
for (int j = -1; j < 2; ++j)
{
int x = row + i, y = col + j;
if (x < 0 || x >= m || y < 0 || y >= n)
{
continue;
}
if (board[x][y] == 'E')
{
vector<int> nextPos{x, y};
updateBoard(board, nextPos);
}
}
}
}
}
return board;
}
};
参考:http://www.cnblogs.com/grandyang/p/6536694.html
最新文章
- 【oracle】 oracle学习笔记1--安装与登录
- iOS UIButton单双击处理响应不同的方法
- rhel7报错整理
- 完善SQL农历转换函数
- Web Service平台概述
- 与众不同 windows phone (44) - 8.0 位置和地图
- PHPNG (next generation)
- JS判断对象类型
- [Angular 2 Router] Configure Your First Angular 2 Route
- 关于layoutSubviews以及drawRect方法
- bc
- Spring、Spring自动扫描和管理Bean
- IIS命令行管理工具使用
- sql-josn
- 使用Selenium进行浏览器自动化操作记录
- eclipse导入项目时,仅项目名出现红叉
- webstorm配置node.js
- python的内置模块re模块方法详解以及使用
- fragment做成选项卡,tab效果。 fragment+RadioGroup
- Manacher算法——求最长回文子串
热门文章
- Mac OS安装Scrapy
- Statelessness Provide credentials with the request. Each request MUST stand alone and should not be affected from previous conversation happened from same client in past.
- Hadoop集群搭建-虚拟机安装(转)(一)
- poj 2228 Naptime(DP的后效性处理)
- HttpServletRequestWrapper模拟实现分布式Session
- hdu 4463 Outlets(最小生成树)
- [Selenium] The most commonly used CSSSelector
- BZOJ_5311_贞鱼_决策单调性+带权二分
- JAVA 中 synchronized 详解
- ul下的li浮动,如何是ul有li的高度