当前位置:网站首页>130. 被圍繞的區域
130. 被圍繞的區域
2022-07-08 00:59: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);
}
};边栏推荐
- Which securities company has a low, safe and reliable account opening commission
- SDNU_ACM_ICPC_2022_Summer_Practice(1~2)
- Implementation of adjacency table of SQLite database storage directory structure 2-construction of directory tree
- New library launched | cnopendata China Time-honored enterprise directory
- Is it safe to speculate in stocks on mobile phones?
- 【深度学习】AI一键换天
- Interface test advanced interface script use - apipost (pre / post execution script)
- Application practice | the efficiency of the data warehouse system has been comprehensively improved! Data warehouse construction based on Apache Doris in Tongcheng digital Department
- ThinkPHP kernel work order system source code commercial open source version multi user + multi customer service + SMS + email notification
- ReentrantLock 公平锁源码 第0篇
猜你喜欢

CVE-2022-28346:Django SQL注入漏洞

5G NR 系统消息

ThinkPHP kernel work order system source code commercial open source version multi user + multi customer service + SMS + email notification

国外众测之密码找回漏洞

取消select的默认样式的向下箭头和设置select默认字样

Redis, do you understand the list

Codeforces Round #804 (Div. 2)(A~D)

Image data preprocessing

jemter分布式

Codeforces Round #804 (Div. 2)(A~D)
随机推荐
大二级分类产品页权重低,不收录怎么办?
Huawei switch s5735s-l24t4s-qa2 cannot be remotely accessed by telnet
语义分割模型库segmentation_models_pytorch的详细使用介绍
[note] common combined filter circuit
Invalid V-for traversal element style
[go record] start go language from scratch -- make an oscilloscope with go language (I) go language foundation
Where is the big data open source project, one-stop fully automated full life cycle operation and maintenance steward Chengying (background)?
STL--String类的常用功能复写
Marubeni official website applet configuration tutorial is coming (with detailed steps)
50Mhz产生时间
股票开户免费办理佣金最低的券商,手机上开户安全吗
Basic types of 100 questions for basic grammar of Niuke
[Yugong series] go teaching course 006 in July 2022 - automatic derivation of types and input and output
13. Model saving and loading
My best game based on wechat applet development
Summary of the third course of weidongshan
Analysis of 8 classic C language pointer written test questions
What does interface testing test?
《因果性Causality》教程,哥本哈根大学Jonas Peters讲授
NTT template for Tourism