We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent aa06033 commit c1637f6Copy full SHA for c1637f6
1 file changed
container-with-most-water/gyeo-ri.py
@@ -1,19 +1,20 @@
1
class Solution:
2
def maxArea(self, height: list[int]) -> int:
3
+ left, right = 0, len(height) - 1
4
max_area = 0
- left_idx = 0
5
- right_idx = len(height) - 1
6
7
- while left_idx < right_idx:
8
- left_h = height[left_idx]
9
- right_h = height[right_idx]
+ while left < right:
+ left_height, right_height = height[left], height[right]
+ min_height = min(left_height, right_height)
+ width = right - left
10
11
- max_area = max(max_area, (right_idx - left_idx) * min(left_h, right_h))
+ current_area = width * min_height
12
+ max_area = max(max_area, current_area)
13
- if left_h < right_h:
14
- left_idx += 1
+ if left_height < right_height:
15
+ left += 1
16
else:
- right_idx -= 1
17
+ right -= 1
18
19
return max_area
20
0 commit comments