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

#include <leetcode.h>

静态 Public 成员函数

static void wallsAndGates (vector< vector< int > > &rooms)
 

详细描述

在文件 leetcode.h2846 行定义.

成员函数说明

◆ wallsAndGates()

void leetcode::walls_and_gates::Solution::wallsAndGates ( vector< vector< int > > &  rooms)
static

在文件 leetcode.cpp7870 行定义.

7870 {
7871 const int m = rooms.size();
7872 const int n = rooms[0].size();
7873 queue<tuple<int, int, int>> q;
7874 for(int i = 0; i < m; i++) {
7875 for(int j = 0; j < n; j++) {
7876 if(rooms[i][j] == 0) {
7877 q.push({0, i, j});
7878 }
7879 }
7880 }
7881 while(!q.empty()) {
7882 auto [d, x, y] = q.front();
7883 q.pop();
7884 pair<int, int> nexts[4] = {{x + 1, y}, {x - 1, y}, {x, y + 1}, {x, y - 1}};
7885 for(auto &[next_x, next_y]: nexts) {
7886 if(next_x >= 0 && next_y >= 0 && next_x < m && next_y < n && rooms[next_x][next_y] != -1 && rooms[next_x][next_y] != 0 && (rooms[next_x][next_y] == INT_MAX || rooms[next_x][next_y] > d + 1)) {
7887 rooms[next_x][next_y] = d + 1;
7888 q.push({d + 1, next_x, next_y});
7889 }
7890 }
7891 }
7892 }

被这些函数引用 leetcode::walls_and_gates::TEST().


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