11-The container with the most water-python

Problem: Given an array, representing the height of the plank. Choose two planks and find the maximum water capacity of the two planks.

def max_area(arrys):
    l,r = 0,len(arrys)-1
    res = 0
    while l<r:
        contain = min(arrys[l],arrys[r])*(r-l)
        if contain>res:
            res = contain
        if arrys[l]<arrys[r]:
            l+=1
        else:
            r-=1
    return res

  Note: Use the strategy of moving the front and back two pointers to the middle to obtain the maximum water storage capacity. The pointer movement strategy is a short side plank movement.

Guess you like

Origin blog.csdn.net/wh672843916/article/details/105503755