Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9b2d37f

Browse files
add 1765
1 parent22bef46 commit9b2d37f

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+
packagecom.fishercoder.solutions;
2+
3+
importjava.util.LinkedList;
4+
importjava.util.Queue;
5+
6+
publicclass_1765 {
7+
publicstaticclassSolution1 {
8+
publicint[][]highestPeak(int[][]isWater) {
9+
intm =isWater.length;
10+
intn =isWater[0].length;
11+
int[][]result =newint[m][n];
12+
Queue<int[]>queue =newLinkedList<>();
13+
for (inti =0;i <m;i++) {
14+
for (intj =0;j <n;j++) {
15+
if (isWater[i][j] ==1) {
16+
queue.offer(newint[]{i,j});
17+
}
18+
}
19+
}
20+
int[]directions =newint[]{0,1,0, -1,0};
21+
intheight =1;
22+
while (!queue.isEmpty()) {
23+
intsize =queue.size();
24+
for (intj =0;j <size;j++) {
25+
int[]curr =queue.poll();
26+
for (inti =0;i <directions.length -1;i++) {
27+
intnewx =directions[i] +curr[0];
28+
intnewy =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(newint[]{newx,newy});
32+
}
33+
}
34+
}
35+
height++;
36+
}
37+
for (inti =0;i <m;i++) {
38+
for (intj =0;j <n;j++) {
39+
if (isWater[i][j] ==1) {
40+
result[i][j] =0;
41+
}
42+
}
43+
}
44+
returnresult;
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp