Skip to content

Commit 1176146

Browse files
committed
solve problem
1 parent 8a2b330 commit 1176146

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
func maxArea(_ height: [Int]) -> Int {
3+
var maxArea = 0
4+
var startPointIndex = 0
5+
var endPointIndex = height.count - 1
6+
while startPointIndex < endPointIndex {
7+
let minHeight = min(height[startPointIndex], height[endPointIndex])
8+
let area = minHeight * (endPointIndex - startPointIndex)
9+
maxArea = max(maxArea, area)
10+
if height[startPointIndex] < height[endPointIndex] {
11+
startPointIndex += 1
12+
} else {
13+
endPointIndex -= 1
14+
}
15+
}
16+
return maxArea
17+
}
18+
}
19+
20+
// Time Complexity O(N)
21+
// Space Complexity O(1)
22+

0 commit comments

Comments
 (0)