当前位置:网站首页>130. Surrounding area
130. Surrounding area
2022-07-08 00:59:00 【anieoo】
Original link :130. The surrounding area
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';
}
}
// From the outer boundary dfs, Put every extendable O Turn into #, It's going on m*n Traverse , Put the rest O Turn into 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);
}
};
边栏推荐
- Stock account opening is free of charge. Is it safe to open an account on your mobile phone
- Codeforces Round #804 (Div. 2)(A~D)
- [go record] start go language from scratch -- make an oscilloscope with go language (I) go language foundation
- What is load balancing? How does DNS achieve load balancing?
- DNS series (I): why does the updated DNS record not take effect?
- ReentrantLock 公平锁源码 第0篇
- Prediction of the victory or defeat of the League of heroes -- simple KFC Colonel
- 完整的模型验证(测试,demo)套路
- SDNU_ ACM_ ICPC_ 2022_ Summer_ Practice(1~2)
- Cve-2022-28346: Django SQL injection vulnerability
猜你喜欢
10.CNN应用于手写数字识别
【GO记录】从零开始GO语言——用GO语言做一个示波器(一)GO语言基础
英雄联盟胜负预测--简易肯德基上校
1293_ Implementation analysis of xtask resumeall() interface in FreeRTOS
3 years of experience, can't you get 20K for the interview and test post? Such a hole?
What does interface testing test?
jemter分布式
Deep dive kotlin synergy (XXII): flow treatment
New library online | cnopendata China Star Hotel data
133. 克隆图
随机推荐
tourist的NTT模板
5g NR system messages
LeetCode刷题
基于人脸识别实现课堂抬头率检测
新库上线 | 中国记者信息数据
【愚公系列】2022年7月 Go教学课程 006-自动推导类型和输入输出
fabulous! How does idea open multiple projects in a single window?
QT adds resource files, adds icons for qaction, establishes signal slot functions, and implements
Huawei switch s5735s-l24t4s-qa2 cannot be remotely accessed by telnet
利用GPU训练网络模型
How is it most convenient to open an account for stock speculation? Is it safe to open an account on your mobile phone
13.模型的保存和载入
SDNU_ACM_ICPC_2022_Summer_Practice(1~2)
Application practice | the efficiency of the data warehouse system has been comprehensively improved! Data warehouse construction based on Apache Doris in Tongcheng digital Department
How does starfish OS enable the value of SFO in the fourth phase of SFO destruction?
[reprint] solve the problem that CONDA installs pytorch too slowly
22年秋招心得
Four stages of sand table deduction in attack and defense drill
第四期SFO销毁,Starfish OS如何对SFO价值赋能?
Interface test advanced interface script use - apipost (pre / post execution script)