Skip to content

Commit 0992313

Browse files
committed
container with most water
1 parent 3c00a21 commit 0992313

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Solution {
2+
func maxArea(_ height: [Int]) -> Int {
3+
var heights = height
4+
var start = 0
5+
var end = heights.count - 1
6+
var maxAmount = 0
7+
8+
while start < end {
9+
let startHeight = heights[start]
10+
let endHeight = heights[end]
11+
let amount = min(startHeight, endHeight) * (end - start)
12+
maxAmount = max(amount, maxAmount)
13+
14+
if startHeight < endHeight {
15+
start += 1
16+
} else {
17+
end -= 1
18+
}
19+
}
20+
21+
return maxAmount
22+
23+
//시간 O(n)
24+
//공간 O(1)
25+
}
26+
}
27+

0 commit comments

Comments
 (0)