Skip to content

Commit b33c397

Browse files
author
Yeqi Tao
committed
Add Soulution.go for 0011.Container With Most Water
1 parent dd4c423 commit b33c397

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+
func maxArea(height []int) int {
2+
maxArea := 0
3+
i := 0
4+
j := len(height) - 1
5+
for i != j {
6+
hi := height[i]
7+
hj := height[j]
8+
maxArea = maxInt(maxArea, (j-i) * minInt(hi, hj))
9+
if hi >= hj {
10+
j--
11+
} else {
12+
i++
13+
}
14+
}
15+
return maxArea
16+
}
17+
18+
func minInt(a, b int) int {
19+
if a >= b {
20+
return b
21+
}
22+
return a
23+
}
24+
25+
func maxInt(a, b int) int {
26+
if a >= b {
27+
return a
28+
}
29+
return b
30+
}

0 commit comments

Comments
 (0)