当前位置:网站首页>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);
}
};
边栏推荐
- [Yugong series] go teaching course 006 in July 2022 - automatic derivation of types and input and output
- Application practice | the efficiency of the data warehouse system has been comprehensively improved! Data warehouse construction based on Apache Doris in Tongcheng digital Department
- AI zhetianchuan ml novice decision tree
- Interface test advanced interface script use - apipost (pre / post execution script)
- Cascade-LSTM: A Tree-Structured Neural Classifier for Detecting Misinformation Cascades(KDD20)
- 6.Dropout应用
- 4.交叉熵
- Letcode43: string multiplication
- From starfish OS' continued deflationary consumption of SFO, the value of SFO in the long run
- 英雄联盟胜负预测--简易肯德基上校
猜你喜欢
14.绘制网络模型结构
国外众测之密码找回漏洞
Course of causality, taught by Jonas Peters, University of Copenhagen
51 communicates with the Bluetooth module, and 51 drives the Bluetooth app to light up
Codeforces Round #804 (Div. 2)(A~D)
接口测试进阶接口脚本使用—apipost(预/后执行脚本)
A network composed of three convolution layers completes the image classification task of cifar10 data set
【GO记录】从零开始GO语言——用GO语言做一个示波器(一)GO语言基础
13. Model saving and loading
AI遮天传 ML-回归分析入门
随机推荐
An error is reported during the process of setting up ADG. Rman-03009 ora-03113
C# ?,?.,?? .....
Which securities company has a low, safe and reliable account opening commission
New library online | information data of Chinese journalists
The method of server defense against DDoS, Hangzhou advanced anti DDoS IP section 103.219.39 x
7.正则化应用
[Yugong series] go teaching course 006 in July 2022 - automatic derivation of types and input and output
Reptile practice (VIII): reptile expression pack
fabulous! How does idea open multiple projects in a single window?
Cancel the down arrow of the default style of select and set the default word of select
QT establish signal slots between different classes and transfer parameters
Introduction to paddle - using lenet to realize image classification method I in MNIST
丸子官网小程序配置教程来了(附详细步骤)
Where is the big data open source project, one-stop fully automated full life cycle operation and maintenance steward Chengying (background)?
v-for遍历元素样式失效
Jemter distributed
A brief history of information by James Gleick
QT adds resource files, adds icons for qaction, establishes signal slot functions, and implements
The weight of the product page of the second level classification is low. What if it is not included?
2.非线性回归