Skip to content

Commit c1637f6

Browse files
committed
fix: 알고리즘은 그대로 유지하되 가독성을 개선
1 parent aa06033 commit c1637f6

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

container-with-most-water/gyeo-ri.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
class Solution:
22
def maxArea(self, height: list[int]) -> int:
3+
left, right = 0, len(height) - 1
34
max_area = 0
4-
left_idx = 0
5-
right_idx = len(height) - 1
65

7-
while left_idx < right_idx:
8-
left_h = height[left_idx]
9-
right_h = height[right_idx]
6+
while left < right:
7+
left_height, right_height = height[left], height[right]
8+
min_height = min(left_height, right_height)
9+
width = right - left
1010

11-
max_area = max(max_area, (right_idx - left_idx) * min(left_h, right_h))
11+
current_area = width * min_height
12+
max_area = max(max_area, current_area)
1213

13-
if left_h < right_h:
14-
left_idx += 1
14+
if left_height < right_height:
15+
left += 1
1516
else:
16-
right_idx -= 1
17+
right -= 1
1718

1819
return max_area
1920

0 commit comments

Comments
 (0)