Skip to content

Commit 791de24

Browse files
committed
Add container with most water solution
1 parent b263e24 commit 791de24

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+
/**
2+
* 시간 복잡도: O(n)
3+
* 공간 복잡도: O(1)
4+
*/
5+
6+
class Solution {
7+
fun maxArea(height: IntArray): Int {
8+
var i = 0
9+
var j = height.size - 1
10+
var max = 0
11+
12+
while (i < j) {
13+
val h = minOf(height[i], height[j])
14+
max = maxOf(max, (j - i) * h)
15+
16+
if (height[i] <= height[j]) i++
17+
else j--
18+
}
19+
20+
return max
21+
}
22+
}

0 commit comments

Comments
 (0)