|
| 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