当前位置:网站首页>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);
}
};边栏推荐
- 13. Enregistrement et chargement des modèles
- 韦东山第三期课程内容概要
- 9.卷积神经网络介绍
- CVE-2022-28346:Django SQL注入漏洞
- Lecture 1: the entry node of the link in the linked list
- ABAP ALV LVC template
- Which securities company has a low, safe and reliable account opening commission
- Malware detection method based on convolutional neural network
- 第四期SFO销毁,Starfish OS如何对SFO价值赋能?
- 手机上炒股安全么?
猜你喜欢

SDNU_ ACM_ ICPC_ 2022_ Summer_ Practice(1~2)

Invalid V-for traversal element style

【obs】官方是配置USE_GPU_PRIORITY 效果为TRUE的

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

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

1293_ Implementation analysis of xtask resumeall() interface in FreeRTOS

NVIDIA Jetson test installation yolox process record

C # generics and performance comparison

51 communicates with the Bluetooth module, and 51 drives the Bluetooth app to light up

Deep dive kotlin synergy (XXII): flow treatment
随机推荐
【深度学习】AI一键换天
13.模型的保存和載入
50Mhz产生时间
华泰证券官方网站开户安全吗?
【愚公系列】2022年7月 Go教学课程 006-自动推导类型和输入输出
Image data preprocessing
C # generics and performance comparison
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
1.线性回归
Password recovery vulnerability of foreign public testing
第一讲:链表中环的入口结点
新库上线 | CnOpenData中华老字号企业名录
Semantic segmentation model base segmentation_ models_ Detailed introduction to pytorch
New library launched | cnopendata China Time-honored enterprise directory
Service mesh introduction, istio overview
德总理称乌不会获得“北约式”安全保障
What does interface testing test?
German prime minister says Ukraine will not receive "NATO style" security guarantee
Analysis of 8 classic C language pointer written test questions
Introduction to paddle - using lenet to realize image classification method I in MNIST