beats 100% ,43ms,Python,time:2016-9-6


  • 0
    J
    class Solution(object):
        def trap(self, height):
            def countListDelta(list_):
                count = 0
                if len(list_)<3:
                    return count
                max_num_in_countListDelta = 0
                for x in range(len(list_)-1):
                    if max_num_in_countListDelta<=list_[x]:
                        max_num_in_countListDelta = list_[x]
                    elif max_num_in_countListDelta>list_[x]:
                        count += max_num_in_countListDelta - list_[x]
                return count
            if len(height)<3:
                return 0
            max_value = max(height)
            index = height.index(max_value)
            front_list = height[0:index]+[max_value]
            behind_list = [max_value]+height[index+1:]
            return countListDelta(front_list) + countListDelta(behind_list[::-1])
    

Log in to reply
 

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