当前位置:网站首页>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);
}
};
边栏推荐
- 50Mhz产生时间
- How is it most convenient to open an account for stock speculation? Is it safe to open an account on your mobile phone
- LeetCode刷题
- Introduction to paddle - using lenet to realize image classification method I in MNIST
- Codeforces Round #804 (Div. 2)(A~D)
- 1.线性回归
- 基础篇——整合第三方技术
- 新库上线 | CnOpenData中华老字号企业名录
- swift获取url参数
- Langchao Yunxi distributed database tracing (II) -- source code analysis
猜你喜欢
新库上线 | CnOpenData中国星级酒店数据
13.模型的保存和載入
FOFA-攻防挑战记录
基于卷积神经网络的恶意软件检测方法
Service mesh introduction, istio overview
Password recovery vulnerability of foreign public testing
第一讲:链表中环的入口结点
Prediction of the victory or defeat of the League of heroes -- simple KFC Colonel
3 years of experience, can't you get 20K for the interview and test post? Such a hole?
Where is the big data open source project, one-stop fully automated full life cycle operation and maintenance steward Chengying (background)?
随机推荐
Basic mode of service mesh
New library online | information data of Chinese journalists
Get started quickly using the local testing tool postman
攻防演练中沙盘推演的4个阶段
完整的模型验证(测试,demo)套路
大二级分类产品页权重低,不收录怎么办?
丸子官网小程序配置教程来了(附详细步骤)
Service mesh introduction, istio overview
Service Mesh的基本模式
10.CNN应用于手写数字识别
Reentrantlock fair lock source code Chapter 0
Fofa attack and defense challenge record
德总理称乌不会获得“北约式”安全保障
国内首次,3位清华姚班本科生斩获STOC最佳学生论文奖
Malware detection method based on convolutional neural network
Is it safe to open an account on the official website of Huatai Securities?
4.交叉熵
5.过拟合,dropout,正则化
C#中string用法
Hotel