1. 程式人生 > >leetcode.11. Container With Most Water

leetcode.11. Container With Most Water

轉向c++了,底乘高,低最大,面積再想大一點就得

class Solution {
public:
    int maxArea(vector<int>& height)
    {
        int maxcon=0;
        int i=0;
        int  h;
        int j=height.size()-1;
        while(i<j)
        {
            h=min(height[i],height[j]);
           //printf("%d %d %d",h,j,i);
            maxcon=max(maxcon,h*(j-i));
            
//printf("\n%d",maxcon); while (height[i]<=h) i++; while (height[j]<=h) j--; } return maxcon; } };

 

保證高不斷拓高,低的那一邊就需要往上升到比原來高的地方才能提高容器。