当前位置:网站首页>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);
}
};边栏推荐
- 10.CNN应用于手写数字识别
- 语义分割模型库segmentation_models_pytorch的详细使用介绍
- New library online | information data of Chinese journalists
- C # generics and performance comparison
- v-for遍历元素样式失效
- Prediction of the victory or defeat of the League of heroes -- simple KFC Colonel
- 牛客基础语法必刷100题之基本类型
- NTT template for Tourism
- Handwriting a simulated reentrantlock
- Basic types of 100 questions for basic grammar of Niuke
猜你喜欢

5.过拟合,dropout,正则化

新库上线 | CnOpenData中国星级酒店数据
![[note] common combined filter circuit](/img/2f/a8c2ef0d76dd7a45b50a64a928a9c8.png)
[note] common combined filter circuit

FOFA-攻防挑战记录

9.卷积神经网络介绍

13. Enregistrement et chargement des modèles

Kubernetes Static Pod (静态Pod)

AI zhetianchuan ml novice decision tree

How does starfish OS enable the value of SFO in the fourth phase of SFO destruction?

12. RNN is applied to handwritten digit recognition
随机推荐
Invalid V-for traversal element style
第四期SFO销毁,Starfish OS如何对SFO价值赋能?
4.交叉熵
股票开户免费办理佣金最低的券商,手机上开户安全吗
[reprint] solve the problem that CONDA installs pytorch too slowly
5g NR system messages
Image data preprocessing
C#中string用法
英雄联盟胜负预测--简易肯德基上校
What has happened from server to cloud hosting?
New library launched | cnopendata China Time-honored enterprise directory
fabulous! How does idea open multiple projects in a single window?
【笔记】常见组合滤波电路
韦东山第二期课程内容概要
ReentrantLock 公平锁源码 第0篇
AI遮天传 ML-回归分析入门
Codeforces Round #804 (Div. 2)(A~D)
My best game based on wechat applet development
国内首次,3位清华姚班本科生斩获STOC最佳学生论文奖
New library online | cnopendata China Star Hotel data