详见: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

最新文章

  1. 【oracle】 oracle学习笔记1--安装与登录
  2. iOS UIButton单双击处理响应不同的方法
  3. rhel7报错整理
  4. 完善SQL农历转换函数
  5. Web Service平台概述
  6. 与众不同 windows phone (44) - 8.0 位置和地图
  7. PHPNG (next generation)
  8. JS判断对象类型
  9. [Angular 2 Router] Configure Your First Angular 2 Route
  10. 关于layoutSubviews以及drawRect方法
  11. bc
  12. Spring、Spring自动扫描和管理Bean
  13. IIS命令行管理工具使用
  14. sql-josn
  15. 使用Selenium进行浏览器自动化操作记录
  16. eclipse导入项目时,仅项目名出现红叉
  17. webstorm配置node.js
  18. python的内置模块re模块方法详解以及使用
  19. fragment做成选项卡,tab效果。 fragment+RadioGroup
  20. Manacher算法——求最长回文子串

热门文章

  1. Mac OS安装Scrapy
  2. 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.
  3. Hadoop集群搭建-虚拟机安装(转)(一)
  4. poj 2228 Naptime(DP的后效性处理)
  5. HttpServletRequestWrapper模拟实现分布式Session
  6. hdu 4463 Outlets(最小生成树)
  7. [Selenium] The most commonly used CSSSelector
  8. BZOJ_5311_贞鱼_决策单调性+带权二分
  9. JAVA 中 synchronized 详解
  10. ul下的li浮动,如何是ul有li的高度