当前位置:网站首页>Leetcode search questions
Leetcode search questions
2022-06-11 01:38:00 【Black white grey 12345】
Catalog
130. The surrounding area

Convert to inverse problem , Starting from the boundary, the depth traversal first marks the non-conforming positions
class Solution {
public:
vector<int> directions {-1, 0, 1, 0, -1};
void dfs(vector<vector<char>>& board, int r, int c) {
board[r][c] = 'A';// use 'A' Mark the unqualified 'O' spot
for (int k = 0; k < 4; ++k) {
int x = r + directions[k], y = c + directions[k+1];
if (x >= 0 && x < board.size() && y >=0 && y < board[0].size() && board[x][y] == 'O') {
dfs(board, x, y);
}
}
}
void solve(vector<vector<char>>& board) {
int m = board.size(), n = board[0].size();
// Traverse two longitudinal boundaries
for (int i = 0; i < m; ++i) {
if (board[i][0] == 'O'){
dfs(board, i, 0);
}
if (board[i][n-1] == 'O'){
dfs(board, i, n-1);
}
}
// Traverse two horizontal boundaries
for (int j = 0; j < n; ++j) {
if (board[0][j] == 'O') {
dfs(board, 0, j);
}
if (board[m-1][j] == 'O') {
dfs(board, m-1, j);
}
}
// According to the traversal of the tag information will meet the conditions 'O' Replace with 'X'
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
if (board[i][j] == 'O') {
board[i][j] = 'X';
}else if (board[i][j] == 'A') {
board[i][j] = 'O'; // Restore the unqualified
}
}
}
}
};边栏推荐
- threejs:如何获得几何体的boundingBox?
- node和express实现mySql模糊搜索
- SAS期末复习知识点总结(应用多元统计实验笔记)
- Clean up the broken artifacts data (.lastUpdated files) and reload the project. Problem resolution
- 北京密云区高新技术企业培育支持标准,补贴10万
- Brief description of custom annotations
- QGC地面站使用教程
- Support standard for cultivation of high-tech enterprises in Changping District, Beijing, with a subsidy of 100000 yuan
- Beijing Fangshan District high tech enterprise cultivation support standard, with a subsidy of 100000 yuan
- 北京房山区高新技术企业培育支持标准,补贴10万
猜你喜欢
![[recommended by Zhihu knowledge master] castle in UAV - focusing on the application of UAV in different technical fields](/img/c6/f1cec6de62e85de446dba7ea8675f0.jpg)
[recommended by Zhihu knowledge master] castle in UAV - focusing on the application of UAV in different technical fields

Middleware_ Redis_ 05_ Persistence of redis

云呐|省级行政单位固定资产管理系统

Yanrong looks at how to realize the optimal storage solution of data Lake in a hybrid cloud environment

Understanding of multithreading

ROS参数服务器

记录打包GoogleChrome浏览器插件

Once you know these treasure websites, you can't live without them!!!

条码固定资产管理系统的作用,固定资产条码化管理

node和express实现mySql模糊搜索
随机推荐
I was so excited about the college entrance examination in 2022
部分 力扣 LeetCode 中的SQL刷题整理
复利的保险理财产品怎么样?可以买吗?
北京門頭溝區高新技術企業培育支持標准,補貼10萬
北京平谷区高新技术企业培育支持标准,补贴10万
Shenzhen Nanshan District specialized special new enterprise application process, with a subsidy of RMB 100000-500000
SAS聚类分析(系统聚类cluster,动态聚类fastclus,变量聚类varclus)
中国专利奖奖金多少,补贴100万
Hao expresses his opinions: what small good habits have you adhered to?
MultipartFile和File互转工具类
Bad RequestThis combination of host and port requires TLS.
项目_基于网络爬虫的疫情数据可视化分析
SQL question brushing and sorting in leetcode of partial deduction
[chess life] 01 life is like chess
Brief description of custom annotations
About mobx
detectron2训练自己的数据集和转coco格式
Project_ Visual analysis of epidemic data based on Web Crawler
使用 CompletableFuture
SAS主成分分析(求相关阵,特征值,单位特征向量,主成分表达式,贡献率和累计贡献率以及进行数据解释)