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

#include <leetcode.h>

静态 Public 成员函数

static vector< vector< int > > highestPeak (vector< vector< int > > &isWater)
 

详细描述

在文件 leetcode.h780 行定义.

成员函数说明

◆ highestPeak()

vector< vector< int > > leetcode::map_of_highest_peak::Solution::highestPeak ( vector< vector< int > > &  isWater)
static

在文件 leetcode.cpp1855 行定义.

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));
1862 }
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));
1868 isWater[i][j] = 0;
1869 occupied[i][j] = true;
1870 } else {
1871 isWater[i][j] = 1;
1872 }
1873 }
1874 }
1875 while(!que.empty()) {
1876 pair<int, int> current = que.front();
1877 que.pop();
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;
1886 que.push(next);
1887 }
1888 }
1889 }
1890 delete[] occupied;
1891 return isWater;
1892 }

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


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