Monday, September 8, 2014

Leetcode: Container With Most Water @Python

An optimal greedy algorithm. A one-pass routine to narrow down the location to search.
class Solution:
    # @return an integer
    def maxArea(self, height):
        L,R,mValue=0,len(height)-1,0
        while L<r: height="" if="" mvalue="max(mValue,min(height[L],height[R])*(R-L))">height[R]:
                R-=1
            else:
                L+=1
        return mValue 

No comments :

Post a Comment