Python code beats 100% submissions in runtime with rather ugly style


  • 0
    K

    0_1472869505581_upload-4c656233-ecd4-4eca-96bc-e242d967ff03

    I'm a green hand on writing python, if you have any suggestion of code style please do not hesitate to tell me.

    class Solution(object):
    def maxArea(self, height):
        """
        :type height: List[int]
        :rtype: int
        """
        debug = False
    	le = len(height)
    	ans = 0
    	i = 0
    	j = le - 1
    	ans = (j - i)*min(height[i], height[j])
    	if debug:
    		print ans
    	recordi = height[i]
    	recordj = height[j]
    	while i < j:
    		if recordi < recordj:
    			while i < j and height[i] <= recordi:
    				i = i + 1
    				if debug:
    					print "i" + str(i)
    			anst = (j - i)*min(height[i], height[j])
    			recordi = height[i]
    			if ans < anst:
    				ans = anst
    		else:
    			while i < j and height[j] <= recordj:
    				j = j - 1
    				if debug:
    					print "j" + str(j)
    			anst = (j - i)*min(height[i], height[j])
    			recordj = height[j]
    			if ans < anst:
    				ans = anst
    
    	return ans

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.