-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path0011.go
44 lines (38 loc) · 958 Bytes
/
0011.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
func maxAreaV2(height []int) int {
left := 0
right := len(height) - 1
maxSize := getTwoMinNumber(height[left], height[right]) * right
for left < right {
if height[left] > height[right] {
right--
} else {
left++
}
tmpMaxSize := getTwoMinNumber(height[left], height[right]) * (right - left)
if tmpMaxSize > maxSize {
maxSize = tmpMaxSize
}
}
return maxSize
}
func maxArea(height []int) int {
maxSize := getTwoMinNumber(height[0], height[1])
for index := 1; index < len(height); index++ {
blockMaxSize := getMaxSize(height, index)
if blockMaxSize > maxSize {
maxSize = blockMaxSize
}
}
return maxSize
}
func getMaxSize(height []int, index int) int {
blockMaxSize := getTwoMinNumber(height[index], height[0]) * index
for i := 1; i < index; i++ {
tmpSize := getTwoMinNumber(height[index], height[i]) * (index - i)
if tmpSize > blockMaxSize {
blockMaxSize = tmpSize
}
}
return blockMaxSize
}