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

Commit10cfc69

Browse files
authored
Create 1642-furthest-building-you-can-reach.kt
1 parentbe87082 commit10cfc69

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
classSolution:
2+
def furthestBuilding(self, heights:List[int], bricks: int, ladders: int)-> int:
3+
heap= []
4+
5+
for iin range(len(heights)-1):
6+
diff= heights[i+1]- heights[i]
7+
if diff<=0:
8+
continue
9+
10+
bricks-= diff
11+
heapq.heappush(heap,-diff)
12+
13+
if bricks<0:
14+
if ladders==0:
15+
return i
16+
ladders-=1
17+
bricks+=-heapq.heappop(heap)
18+
19+
return len(heights)-1

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp