GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — leetcode/python/011_Container_With_Most_Water.py at master · 539961733/leetcode Expand file tree/ Copy path011_Container_With_Most_Water.pyMore file actions 43 lines (42 loc) · 1.25 KB / Copy path011_Container_With_Most_Water.pyFile metadata and controls43 lines (42 loc) · 1.25 KB 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 # class Solution(object): # def maxArea(self, height): # """ # :type height: List[int] # :rtype: int # """ class Solution(object): # def maxArea(self, height): # # brute force # ls = len(height) # left, right = 0, ls - 1 # result = 0 # while left < right: # result = max(min(height[left], height[right]) * (right - left), result) # if height[left] > height[right]: # right -= 1 # else: # left += 1 # return result def maxArea(self, height): # skip some choices ls = len(height) lm = min(height[0], height[ls - 1]) max_v = lm * (ls - 1) low = 0 high = ls - 1 while low < high: while height[low] < lm and low < ls: low += 1 while height[high] < lm and high < ls: high -= 1 if low > high: break m = min(height[low], height[high]) if m * (high - low) > max_v: max_v = m * (high - low) lm = m if height[low] < height[high]: low += 1 else: high -= 1 return max_v |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |