Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 23a5610

Browse files
committed
leetcode: add 1765
1 parent bc6cd84 commit 23a5610

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

LeetCode/1765.Map Of Highest Peak.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
typedef long long ll ;
6+
const ll INF=1e18;
7+
const ll mod1=1e9+7;
8+
const ll mod2=998244353;
9+
//Add main code here
10+
11+
class Solution
12+
{
13+
public:
14+
int x[4] = {1, -1, 0, 0};
15+
int y[4] = {0, 0, -1, 1};
16+
vector<vector<int>> highestPeak(vector<vector<int>> &isWater)
17+
{
18+
int n = isWater.size();
19+
int m = isWater[0].size();
20+
vector<vector<int>> ans(n, vector<int>(m, -1));
21+
queue<pair<int, int>> q;
22+
23+
for (int i = 0; i < n; i++)
24+
{
25+
for (int j = 0; j < m; j++)
26+
{
27+
if (isWater[i][j] == 1)
28+
{
29+
ans[i][j] = 0;
30+
q.push({i, j});
31+
}
32+
}
33+
}
34+
35+
while (!q.empty())
36+
{
37+
auto top = q.front();
38+
q.pop();
39+
40+
for (int i = 0; i < 4; i++)
41+
{
42+
int newI = top.first + y[i];
43+
int newJ = top.second + x[i];
44+
45+
if (newI >= 0 && newI < n && newJ >= 0 && newJ < m &&
46+
ans[newI][newJ] == -1)
47+
{
48+
ans[newI][newJ] = ans[top.first][top.second] + 1;
49+
q.push({newI, newJ});
50+
}
51+
}
52+
}
53+
return ans;
54+
}
55+
};

0 commit comments

Comments
 (0)