当前位置:网站首页>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);
}
};
边栏推荐
- Summary of the third course of weidongshan
- Binder core API
- 股票开户免费办理佣金最低的券商,手机上开户安全吗
- 12. RNN is applied to handwritten digit recognition
- How does starfish OS enable the value of SFO in the fourth phase of SFO destruction?
- 13.模型的保存和載入
- My best game based on wechat applet development
- 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
- 9.卷积神经网络介绍
- 串口接收一包数据
猜你喜欢
10.CNN应用于手写数字识别
New library online | cnopendata China Star Hotel data
A network composed of three convolution layers completes the image classification task of cifar10 data set
51 communicates with the Bluetooth module, and 51 drives the Bluetooth app to light up
5.过拟合,dropout,正则化
新库上线 | CnOpenData中国星级酒店数据
5g NR system messages
国外众测之密码找回漏洞
基于微信小程序开发的我最在行的小游戏
13.模型的保存和载入
随机推荐
【obs】Impossible to find entrance point CreateDirect3D11DeviceFromDXGIDevice
Thinkphp内核工单系统源码商业开源版 多用户+多客服+短信+邮件通知
9.卷积神经网络介绍
串口接收一包数据
Summary of the third course of weidongshan
Kubernetes Static Pod (静态Pod)
Kubernetes static pod (static POD)
7.正则化应用
4.交叉熵
Cancel the down arrow of the default style of select and set the default word of select
Cascade-LSTM: A Tree-Structured Neural Classifier for Detecting Misinformation Cascades(KDD20)
13. Enregistrement et chargement des modèles
My best game based on wechat applet development
Summary of weidongshan phase II course content
Service mesh introduction, istio overview
Hotel
Lecture 1: the entry node of the link in the linked list
Leetcode brush questions
Class head up rate detection based on face recognition
股票开户免费办理佣金最低的券商,手机上开户安全吗