#include <leetcode.h>
◆ numEnclaves()
int leetcode::number_of_enclaves::Solution::numEnclaves |
( |
vector< vector< int > > & |
grid | ) |
|
|
static |
在文件 leetcode.cpp 第 2676 行定义.
2678 const int m = grid.size();
2679 const int n = grid[0].size();
2680 auto que = queue<pair<int, int>>();
2681 for(
int i = 0; i < m; i++) {
2682 for(
int j = 0; j < n; j++) {
2683 if(grid[i][j] == 1) {
2685 if(i == 0 || i == m - 1 || j == 0 || j == n - 1) {
2686 que.push(make_pair(i, j));
2692 while(!que.empty()) {
2693 auto [x, y] = que.front();
2696 pair<int, int> nexts[4] = {make_pair(x + 1, y), make_pair(x - 1, y), make_pair(x, y + 1), make_pair(x, y - 1)};
2697 for(
auto next: nexts) {
2698 auto [next_x, next_y] = next;
2699 if(0 <= next_x && next_x < m && 0 <= next_y && next_y < n && grid[next_x][next_y] != 0) {
2701 grid[next_x][next_y] = 0;
被这些函数引用 leetcode::number_of_enclaves::TEST().
该类的文档由以下文件生成: