当前位置:网站首页>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);
}
};边栏推荐
- New library online | cnopendata China Star Hotel data
- C# ?,?.,?? .....
- Reentrantlock fair lock source code Chapter 0
- Malware detection method based on convolutional neural network
- CVE-2022-28346:Django SQL注入漏洞
- Basic mode of service mesh
- How is it most convenient to open an account for stock speculation? Is it safe to open an account on your mobile phone
- 手写一个模拟的ReentrantLock
- 6.Dropout应用
- 攻防演练中沙盘推演的4个阶段
猜你喜欢

NVIDIA Jetson test installation yolox process record

13. Enregistrement et chargement des modèles

赞!idea 如何单窗口打开多个项目?

New library launched | cnopendata China Time-honored enterprise directory

Tapdata 的 2.0 版 ,开源的 Live Data Platform 现已发布

RPA cloud computer, let RPA out of the box with unlimited computing power?

2.非线性回归
![[go record] start go language from scratch -- make an oscilloscope with go language (I) go language foundation](/img/76/b048e100d2c964ac00bc4f64e97e7a.png)
[go record] start go language from scratch -- make an oscilloscope with go language (I) go language foundation

After going to ByteDance, I learned that there are so many test engineers with an annual salary of 40W?

FOFA-攻防挑战记录
随机推荐
New library online | information data of Chinese journalists
Fofa attack and defense challenge record
Cascade-LSTM: A Tree-Structured Neural Classifier for Detecting Misinformation Cascades(KDD20)
【愚公系列】2022年7月 Go教学课程 006-自动推导类型和输入输出
Implementation of adjacency table of SQLite database storage directory structure 2-construction of directory tree
QT establish signal slots between different classes and transfer parameters
手机上炒股安全么?
Hotel
Kubernetes static pod (static POD)
ReentrantLock 公平锁源码 第0篇
10.CNN应用于手写数字识别
Qt添加资源文件,为QAction添加图标,建立信号槽函数并实现
v-for遍历元素样式失效
国外众测之密码找回漏洞
Invalid V-for traversal element style
Lecture 1: the entry node of the link in the linked list
RPA cloud computer, let RPA out of the box with unlimited computing power?
Service Mesh介绍,Istio概述
4.交叉熵
串口接收一包数据