当前位置:网站首页>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);
}
};边栏推荐
- Reptile practice (VIII): reptile expression pack
- 手写一个模拟的ReentrantLock
- 攻防演练中沙盘推演的4个阶段
- 牛客基础语法必刷100题之基本类型
- Introduction to paddle - using lenet to realize image classification method I in MNIST
- Marubeni official website applet configuration tutorial is coming (with detailed steps)
- Qt添加资源文件,为QAction添加图标,建立信号槽函数并实现
- SDNU_ACM_ICPC_2022_Summer_Practice(1~2)
- 赞!idea 如何单窗口打开多个项目?
- Qt不同类之间建立信号槽,并传递参数
猜你喜欢

10.CNN应用于手写数字识别

QT establish signal slots between different classes and transfer parameters

接口测试进阶接口脚本使用—apipost(预/后执行脚本)

fabulous! How does idea open multiple projects in a single window?

接口测试要测试什么?

DNS series (I): why does the updated DNS record not take effect?

Application practice | the efficiency of the data warehouse system has been comprehensively improved! Data warehouse construction based on Apache Doris in Tongcheng digital Department

利用GPU训练网络模型

《因果性Causality》教程,哥本哈根大学Jonas Peters讲授

1293_ Implementation analysis of xtask resumeall() interface in FreeRTOS
随机推荐
A network composed of three convolution layers completes the image classification task of cifar10 data set
ReentrantLock 公平锁源码 第0篇
Hotel
After going to ByteDance, I learned that there are so many test engineers with an annual salary of 40W?
Summary of the third course of weidongshan
Semantic segmentation model base segmentation_ models_ Detailed introduction to pytorch
What if the testing process is not perfect and the development is not active?
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
股票开户免费办理佣金最低的券商,手机上开户安全吗
Analysis of 8 classic C language pointer written test questions
取消select的默认样式的向下箭头和设置select默认字样
Invalid V-for traversal element style
13.模型的保存和載入
[note] common combined filter circuit
Basic types of 100 questions for basic grammar of Niuke
NVIDIA Jetson test installation yolox process record
[necessary for R & D personnel] how to make your own dataset and display it.
基于微信小程序开发的我最在行的小游戏
Introduction to paddle - using lenet to realize image classification method I in MNIST
Prediction of the victory or defeat of the League of heroes -- simple KFC Colonel