望着时间滴答滴答的流过,我不曾改变过 . . .

11. Container With Most Water

        int res = 0;
        int ab = 0;
        for(int i = 0;i < height.length; i++){
            for (int j = i +1; j < height.length; j++){
                ab = Math.min(height[i], height[j])* (j - i);
                res = Math.max(res, ab);
            }
        }
        return res;
        int low = 0, high = height.length - 1 ;
        int res = 0;
        while (low < high){
            int tlo = height[low], thi = height[high];
            int ab = Math.min(tlo, thi) * (high - low);
            res = Math.max(res, ab);
            
            **if (tlo <= thi)**
                **while (low < high && height[low] <= tlo) low++;**
            **else**
                **while (low < high && height[high] <= thi) high--;**
        }
        
        return res;
posted @ 2019-04-07 09:10  whyaza  阅读(104)  评论(0编辑  收藏  举报