Skip to content

Commit fbff392

Browse files
committed
feat: Add solution for LeetCode problem 11
1 parent 74db2c7 commit fbff392

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// 11. Container With Most Water
3+
// https://leetcode.com/problems/container-with-most-water/description/
4+
// Dale-Study
5+
//
6+
// Created by WhiteHyun on 2024/06/08.
7+
//
8+
9+
class Solution {
10+
func maxArea(_ height: [Int]) -> Int {
11+
var totalArea = 0
12+
var left = 0
13+
var right = height.endIndex - 1
14+
15+
while left < right {
16+
let area = (right - left) * min(height[left], height[right])
17+
if area > totalArea {
18+
totalArea = area
19+
}
20+
21+
if height[left] < height[right] {
22+
left += 1
23+
} else {
24+
right -= 1
25+
}
26+
}
27+
28+
return totalArea
29+
}
30+
}

0 commit comments

Comments
 (0)