problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
leetcode::surrounded_regions::Solution类 参考

#include <leetcode.h>

静态 Public 成员函数

static void dfs (vector< vector< char > > &board, int x, int y)
 
static void solve (vector< vector< char > > &board)
 

详细描述

在文件 leetcode.h2381 行定义.

成员函数说明

◆ dfs()

void leetcode::surrounded_regions::Solution::dfs ( vector< vector< char > > &  board,
int  x,
int  y 
)
static

在文件 leetcode.cpp6393 行定义.

6393 {
6394 board[x][y] = 'D';
6395 const int m = board.size();
6396 const int n = board[0].size();
6397 pair<int, int> nexts[4] = {{x - 1, y}, {x + 1, y}, {x, y - 1}, {x, y + 1}};
6398 for(auto [next_x, next_y]: nexts) {
6399 if(next_x >= 0 && next_x < m && next_y >= 0 && next_y < n && board[next_x][next_y] == 'O') {
6400 dfs(board, next_x, next_y);
6401 }
6402 }
6403 }
static void dfs(vector< vector< char > > &board, int x, int y)
Definition: leetcode.cpp:6393

引用了 dfs().

被这些函数引用 dfs() , 以及 solve().

◆ solve()

void leetcode::surrounded_regions::Solution::solve ( vector< vector< char > > &  board)
static

在文件 leetcode.cpp6362 行定义.

6362 {
6363 const int m = board.size();
6364 const int n = board[0].size();
6365 for(int i = 0; i < n; i++) {
6366 if(board[0][i] == 'O') {
6367 dfs(board, 0, i);
6368 }
6369 if(board[m - 1][i] == 'O') {
6370 dfs(board, m - 1, i);
6371 }
6372 }
6373 for(int j = 0; j < m; j++) {
6374 if(board[j][0] == 'O') {
6375 dfs(board, j, 0);
6376 }
6377 if(board[j][n - 1] == 'O') {
6378 dfs(board, j, n - 1);
6379 }
6380 }
6381 for(int i = 0; i < m; i++) {
6382 for(int j = 0; j < n; j++) {
6383 if(board[i][j] == 'O') {
6384 board[i][j] = 'X';
6385 }
6386 if(board[i][j] == 'D') {
6387 board[i][j] = 'O';
6388 }
6389 }
6390 }
6391 }

引用了 dfs().


该类的文档由以下文件生成: