Skip to content

Latest commit

 

History

History
28 lines (26 loc) · 414 Bytes

林浩特-20180810.md

File metadata and controls

28 lines (26 loc) · 414 Bytes

【leetcode 算法题】

https://leetcode.com/problems/container-with-most-water/description/

func maxArea(height []int) int {
	max:=0
	lo:=0
	hi:=len(height)-1
	for lo < hi {
		min := 0
		if height[lo]>=height[hi] {
			min = height[hi]
		} else {
			min = height[lo]
		}
		if min*(hi-lo) >= max {
			max = min*(hi-lo)
		}
		if height[lo]>=height[hi] {
			hi--
		} else {
			lo++
		}
	}
	return max
}