Skip to content

Commit 52bdc09

Browse files
authored
Merge pull request neetcode-gh#651 from MaratKhakim/11-Container-with-Most-Water
11. Container with Most Water Go
2 parents 580725d + edbc922 commit 52bdc09

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

go/11-Container-with-Most-Water.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
func maxArea(height []int) int {
2+
left := 0
3+
right := len(height) - 1
4+
res := 0
5+
6+
for left < right {
7+
area := min(height[left], height[right]) * (right - left)
8+
9+
if area > res {
10+
res = area
11+
}
12+
13+
if height[left] > height[right] {
14+
right--
15+
} else {
16+
left++
17+
}
18+
}
19+
20+
return res
21+
}
22+
23+
func min(a, b int) int {
24+
if a < b {
25+
return a
26+
}
27+
return b
28+
}

0 commit comments

Comments
 (0)