当前位置:网站首页>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);
}
};
边栏推荐
- 【obs】Impossible to find entrance point CreateDirect3D11DeviceFromDXGIDevice
- 新库上线 | CnOpenData中国星级酒店数据
- Class head up rate detection based on face recognition
- fabulous! How does idea open multiple projects in a single window?
- 22年秋招心得
- 基于微信小程序开发的我最在行的小游戏
- Deep dive kotlin collaboration (the end of 23): sharedflow and stateflow
- Deep dive kotlin synergy (XXII): flow treatment
- 新库上线 | 中国记者信息数据
- Service Mesh介绍,Istio概述
猜你喜欢
Interface test advanced interface script use - apipost (pre / post execution script)
Semantic segmentation model base segmentation_ models_ Detailed introduction to pytorch
【愚公系列】2022年7月 Go教学课程 006-自动推导类型和输入输出
[Yugong series] go teaching course 006 in July 2022 - automatic derivation of types and input and output
Prediction of the victory or defeat of the League of heroes -- simple KFC Colonel
ReentrantLock 公平锁源码 第0篇
完整的模型训练套路
Image data preprocessing
接口测试进阶接口脚本使用—apipost(预/后执行脚本)
Lecture 1: the entry node of the link in the linked list
随机推荐
13. Enregistrement et chargement des modèles
Semantic segmentation model base segmentation_ models_ Detailed introduction to pytorch
An error is reported during the process of setting up ADG. Rman-03009 ora-03113
国外众测之密码找回漏洞
[OBS] the official configuration is use_ GPU_ Priority effect is true
10.CNN应用于手写数字识别
Malware detection method based on convolutional neural network
Service Mesh介绍,Istio概述
Fofa attack and defense challenge record
STL--String类的常用功能复写
Deep dive kotlin collaboration (the end of 23): sharedflow and stateflow
Is it safe to speculate in stocks on mobile phones?
Cancel the down arrow of the default style of select and set the default word of select
[necessary for R & D personnel] how to make your own dataset and display it.
Qt不同类之间建立信号槽,并传递参数
手写一个模拟的ReentrantLock
SDNU_ ACM_ ICPC_ 2022_ Summer_ Practice(1~2)
Application practice | the efficiency of the data warehouse system has been comprehensively improved! Data warehouse construction based on Apache Doris in Tongcheng digital Department
Introduction to paddle - using lenet to realize image classification method II in MNIST
11.递归神经网络RNN