当前位置:网站首页>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);
}
};
边栏推荐
- Cascade-LSTM: A Tree-Structured Neural Classifier for Detecting Misinformation Cascades(KDD20)
- 1293_ Implementation analysis of xtask resumeall() interface in FreeRTOS
- 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
- 牛客基础语法必刷100题之基本类型
- What has happened from server to cloud hosting?
- ThinkPHP kernel work order system source code commercial open source version multi user + multi customer service + SMS + email notification
- 【愚公系列】2022年7月 Go教学课程 006-自动推导类型和输入输出
- 新库上线 | CnOpenData中华老字号企业名录
- Qt不同类之间建立信号槽,并传递参数
- Invalid V-for traversal element style
猜你喜欢
C # generics and performance comparison
Service mesh introduction, istio overview
5g NR system messages
3 years of experience, can't you get 20K for the interview and test post? Such a hole?
4.交叉熵
Introduction to ML regression analysis of AI zhetianchuan
Kubernetes static pod (static POD)
Reentrantlock fair lock source code Chapter 0
A network composed of three convolution layers completes the image classification task of cifar10 data set
ThinkPHP kernel work order system source code commercial open source version multi user + multi customer service + SMS + email notification
随机推荐
韦东山第二期课程内容概要
Service mesh introduction, istio overview
LeetCode刷题
22年秋招心得
Leetcode brush questions
[OBS] the official configuration is use_ GPU_ Priority effect is true
13.模型的保存和載入
Basic mode of service mesh
5.过拟合,dropout,正则化
v-for遍历元素样式失效
Basic types of 100 questions for basic grammar of Niuke
Deep dive kotlin synergy (XXII): flow treatment
Hotel
大二级分类产品页权重低,不收录怎么办?
CVE-2022-28346:Django SQL注入漏洞
Cause analysis and solution of too laggy page of [test interview questions]
Cascade-LSTM: A Tree-Structured Neural Classifier for Detecting Misinformation Cascades(KDD20)
利用GPU训练网络模型
Cascade-LSTM: A Tree-Structured Neural Classifier for Detecting Misinformation Cascades(KDD20)
letcode43:字符串相乘