当前位置:网站首页>130. 被围绕的区域
130. 被围绕的区域
2022-07-07 23:18:00 【anieoo】
原题链接:130. 被围绕的区域
solution:
dfs
class Solution {
public:
void solve(vector<vector<char>>& board) {
int m = board.size(),n = board[0].size();
for(int i = 0;i < m;i++) {
dfs(board, i, 0);
dfs(board, i, n - 1);
}
for(int j = 0;j < n;j++) {
dfs(board, 0, j);
dfs(board, m - 1, j);
}
for(int i = 0;i < m;i++)
for(int j = 0;j < n;j++) {
if(board[i][j] == '#') board[i][j] = 'O';
else if(board[i][j] == 'O') board[i][j] = 'X';
}
}
//从外边界dfs,将每一个可以延伸的O变为#,在进行m*n遍历,将剩余的O变为X
void dfs(vector<vector<char>> &board, int x,int y) {
if(x < 0 || x == board.size() || y < 0 || y == board[0].size() || board[x][y] != 'O') return;
board[x][y] = '#';
dfs(board, x + 1, y);
dfs(board, x, y + 1);
dfs(board, x - 1, y);
dfs(board, x, y - 1);
}
};边栏推荐
- 炒股开户怎么最方便,手机上开户安全吗
- Reptile practice (VIII): reptile expression pack
- QT adds resource files, adds icons for qaction, establishes signal slot functions, and implements
- 国内首次,3位清华姚班本科生斩获STOC最佳学生论文奖
- [reprint] solve the problem that CONDA installs pytorch too slowly
- Malware detection method based on convolutional neural network
- New library online | cnopendata China Star Hotel data
- How does starfish OS enable the value of SFO in the fourth phase of SFO destruction?
- 手机上炒股安全么?
- Prediction of the victory or defeat of the League of heroes -- simple KFC Colonel
猜你喜欢

英雄联盟胜负预测--简易肯德基上校

Jemter distributed

letcode43:字符串相乘

NVIDIA Jetson测试安装yolox过程记录

2.非线性回归

Malware detection method based on convolutional neural network

Redis, do you understand the list

What if the testing process is not perfect and the development is not active?

Letcode43: string multiplication

8道经典C语言指针笔试题解析
随机推荐
New library launched | cnopendata China Time-honored enterprise directory
What is load balancing? How does DNS achieve load balancing?
9.卷积神经网络介绍
Thinkphp内核工单系统源码商业开源版 多用户+多客服+短信+邮件通知
2022-07-07: the original array is a monotonic array with numbers greater than 0 and less than or equal to K. there may be equal numbers in it, and the overall trend is increasing. However, the number
攻防演练中沙盘推演的4个阶段
CVE-2022-28346:Django SQL注入漏洞
Qt添加资源文件,为QAction添加图标,建立信号槽函数并实现
"An excellent programmer is worth five ordinary programmers", and the gap lies in these seven key points
A network composed of three convolution layers completes the image classification task of cifar10 data set
Which securities company has a low, safe and reliable account opening commission
fabulous! How does idea open multiple projects in a single window?
韦东山第三期课程内容概要
Where is the big data open source project, one-stop fully automated full life cycle operation and maintenance steward Chengying (background)?
NVIDIA Jetson测试安装yolox过程记录
[note] common combined filter circuit
Service Mesh介绍,Istio概述
国外众测之密码找回漏洞
2.非线性回归
They gathered at the 2022 ecug con just for "China's technological power"