Skip to content

Commit c2fbe6f

Browse files
authored
container with most water solution
1 parent f938d33 commit c2fbe6f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
func maxArea(height []int) int {
2+
ans := 0
3+
i, j := 0, len(height) - 1
4+
for i < j {
5+
dh := height[i] - height[j]
6+
dx := j - i
7+
k := j
8+
if dh == 0 {
9+
i++
10+
j--
11+
} else if dh > 0 {
12+
j--
13+
} else {
14+
k = i
15+
i++
16+
}
17+
ans = max(ans, dx * height[k])
18+
}
19+
return ans
20+
}

0 commit comments

Comments
 (0)