Skip to content

Commit e336881

Browse files
authored
feat: [LeetCode #1732] Find The Highest Altitude (#5)
Тип: prefix sum Сложность: easy Временная сложность: O(n) Пространственная сложность: O(1) - Ссылка: https://leetcode.com/problems/find-the-highest-altitude/
1 parent 4bbbbda commit e336881

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

src/prefix_sum/__init__.py

Whitespace-only changes.

src/prefix_sum/find_the_highest_altitude/__init__.py

Whitespace-only changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def largestAltitude(self, gain: List[int]) -> int:
6+
current_altitude = 0
7+
max_altitude = 0
8+
9+
for change in gain:
10+
current_altitude += change
11+
max_altitude = max(max_altitude, current_altitude)
12+
13+
return max_altitude
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import pytest
2+
from src.prefix_sum.find_the_highest_altitude.solution import Solution
3+
4+
5+
@pytest.mark.parametrize(
6+
"gain, expected",
7+
[
8+
([-5, 1, 5, 0, -7], 1),
9+
([-4, -3, -2, -1, 4, 3, 2], 0),
10+
],
11+
)
12+
def test_largest_altitude(gain, expected):
13+
solution = Solution()
14+
assert solution.largestAltitude(gain) == expected

0 commit comments

Comments
 (0)