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

Commitbe87082

Browse files
authored
Create 1642-furthest-building-you-can-reach.kt
1 parenta00e692 commitbe87082

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
classSolution {
2+
funfurthestBuilding(heights:IntArray,bricks:Int,ladders:Int):Int {
3+
val maxHeap=PriorityQueue<Int> { a, b-> b- a }
4+
var bricks= bricks
5+
var ladders= ladders
6+
7+
for (iin0 until heights.lastIndex) {
8+
val diff= heights[i+1]- heights[i]
9+
if (diff<=0)continue
10+
11+
bricks= bricks- diff
12+
maxHeap.add(diff)
13+
14+
if (bricks<0) {
15+
if (ladders==0)return i
16+
ladders-=1
17+
bricks+= maxHeap.poll()
18+
}
19+
}
20+
21+
return heights.lastIndex
22+
}
23+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp