Skip to content

Commit 9b2d37f

Browse files
add 1765
1 parent 22bef46 commit 9b2d37f

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1765|[Map of Highest Peak](https://leetcode.com/problems/map-of-highest-peak/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1765.java) ||Medium|BFS, Graph|
1112
|1764|[Form Array by Concatenating Subarrays of Another Array](https://leetcode.com/problems/form-array-by-concatenating-subarrays-of-another-array/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1764.java) ||Medium|Array, Greedy|
1213
|1763|[Longest Nice Substring](https://leetcode.com/problems/longest-nice-substring/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1763.java) ||Easy|String|
1314
|1759|[Count Number of Homogenous Substrings](https://leetcode.com/problems/count-number-of-homogenous-substrings/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1758.java) ||Medium|String ,Greedy|
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.LinkedList;
4+
import java.util.Queue;
5+
6+
public class _1765 {
7+
public static class Solution1 {
8+
public int[][] highestPeak(int[][] isWater) {
9+
int m = isWater.length;
10+
int n = isWater[0].length;
11+
int[][] result = new int[m][n];
12+
Queue<int[]> queue = new LinkedList<>();
13+
for (int i = 0; i < m; i++) {
14+
for (int j = 0; j < n; j++) {
15+
if (isWater[i][j] == 1) {
16+
queue.offer(new int[]{i, j});
17+
}
18+
}
19+
}
20+
int[] directions = new int[]{0, 1, 0, -1, 0};
21+
int height = 1;
22+
while (!queue.isEmpty()) {
23+
int size = queue.size();
24+
for (int j = 0; j < size; j++) {
25+
int[] curr = queue.poll();
26+
for (int i = 0; i < directions.length - 1; i++) {
27+
int newx = directions[i] + curr[0];
28+
int newy = directions[i + 1] + curr[1];
29+
if (newx >= 0 && newx < m && newy >= 0 && newy < n && result[newx][newy] == 0) {
30+
result[newx][newy] = height;
31+
queue.offer(new int[]{newx, newy});
32+
}
33+
}
34+
}
35+
height++;
36+
}
37+
for (int i = 0; i < m; i++) {
38+
for (int j = 0; j < n; j++) {
39+
if (isWater[i][j] == 1) {
40+
result[i][j] = 0;
41+
}
42+
}
43+
}
44+
return result;
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)