Skip to content

Commit 334b616

Browse files
committed
Create 1732-FindTheHighestAltitude.py
1 parent 2e0b1fc commit 334b616

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/1732-FindTheHighestAltitude.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python3
2+
"""
3+
CREATED AT: 2022-11-19
4+
5+
URL: https://leetcode.com/problems/find-the-highest-altitude/
6+
7+
GITHUB: https://github.com/Jiezhi/myleetcode
8+
9+
FileName: 1732-FindTheHighestAltitude
10+
11+
Difficulty: Easy
12+
13+
Desc:
14+
15+
Tag:
16+
17+
See:
18+
19+
"""
20+
from tool import *
21+
22+
23+
class Solution:
24+
def largestAltitude(self, gain: List[int]) -> int:
25+
"""
26+
Runtime: 77 ms, faster than 18.16%
27+
Memory Usage: 13.9 MB, less than 9.99%
28+
n == gain.length
29+
1 <= n <= 100
30+
-100 <= gain[i] <= 100
31+
"""
32+
return max(itertools.accumulate(gain, initial=0))
33+
34+
35+
def test():
36+
assert Solution().largestAltitude(gain=[-5, 1, 5, 0, -7]) == 1
37+
assert Solution().largestAltitude(gain=[-4, -3, -2, -1, 4, 3, 2]) == 0
38+
39+
40+
if __name__ == '__main__':
41+
test()

0 commit comments

Comments
 (0)