Container With Most Water II


  • 0
    T

    If I change the question like this:

    Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, between these two lines(include), we use straight lines to connect all the adjacent endpoints (i, ai) (e.g. (i, ai) and (i+1, a(i+ 1)) are connected because they are adjcent endpoints). The two vertical lines, x-axis, and the lines we draw forms a container, such that the container contains the most water.

    Note: You may not slant the container.

    Dose this problem has a O(n) solution?


Log in to reply
 

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