Skip to content

Commit 2b62a21

Browse files
author
hero
committed
盛最多水的容器
1 parent 257c33c commit 2b62a21

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

leet_code/isMatch_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ func TestIsMatch(t *testing.T) {
77
}
88

99
func isMatch(s string, p string) bool {
10+
1011
return true
1112
}

leet_code/maxArea_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package leet_code
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestMaxArea(t *testing.T) {
8+
t.Log(maxArea([]int{1, 8, 6, 2, 5, 4, 8, 3, 7}))
9+
}
10+
11+
func maxArea(height []int) int {
12+
var (
13+
startIndex int
14+
endIndex int = len(height) - 1
15+
max int
16+
)
17+
for i := 0; i < len(height); i++ {
18+
var (
19+
min int
20+
)
21+
indexStart := startIndex
22+
indexEnd := endIndex
23+
if height[startIndex] < height[endIndex] {
24+
min = height[startIndex]
25+
startIndex++
26+
} else {
27+
min = height[endIndex]
28+
endIndex--
29+
}
30+
if min*(indexEnd-indexStart) >= max {
31+
max = min * (indexEnd - indexStart)
32+
}
33+
}
34+
return max
35+
}

0 commit comments

Comments
 (0)