#include <leetcode.h>
|
static vector< vector< int > > | highestPeak (vector< vector< int > > &isWater) |
|
◆ highestPeak()
vector< vector< int > > leetcode::map_of_highest_peak::Solution::highestPeak |
( |
vector< vector< int > > & |
isWater | ) |
|
|
static |
在文件 leetcode.cpp 第 1855 行定义.
1856 const int m = isWater.size();
1857 const int n = isWater[0].size();
1858 auto *occupied =
new bool *[m];
1859 for(
int i = 0; i < m; i++) {
1860 occupied[i] =
new bool[n];
1861 memset(occupied[i], 0, n *
sizeof(
bool));
1863 auto que = queue<pair<int, int>>();
1864 for(
int i = 0; i < m; i++) {
1865 for(
int j = 0; j < n; j++) {
1866 if(isWater[i][j] == 1) {
1867 que.push(pair(i, j));
1869 occupied[i][j] =
true;
1875 while(!que.empty()) {
1876 pair<int, int> current = que.front();
1878 pair<int, int> nexts[4] = {pair(current.first + 1, current.second),
1879 pair(current.first - 1, current.second),
1880 pair(current.first, current.second + 1),
1881 pair(current.first, current.second - 1)};
1882 for(
auto next: nexts) {
1883 if(0 <= next.first && next.first < m && 0 <= next.second && next.second < n && !occupied[next.first][next.second]) {
1884 isWater[next.first][next.second] = isWater[current.first][current.second] + 1;
1885 occupied[next.first][next.second] =
true;
被这些函数引用 leetcode::map_of_highest_peak::TEST().
该类的文档由以下文件生成: