首页 > 其他 > 详细

LeetCode Container With Most Water

时间:2014-05-08 10:24:06      阅读:519      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
class Solution{
    public:
        int maxArea(vector<int>& height) {  
        int len = height.size(), low = 0, high = len -1 ;  
        int maxArea = 0;  
        while (low < high) {  
            maxArea = max(maxArea, (high - low) * min(height[low], height[high]));  
            if (height[low] < height[high]) {  
                low++;  
            } else {  
                high--;  
            }  
        }  
        return maxArea;  
    }
};
bubuko.com,布布扣

应该算是贪婪算法吧,直接从disscus里抄了,自己只能想出一个nlogn的,对贪婪没什么感觉,想不到

LeetCode Container With Most Water,布布扣,bubuko.com

LeetCode Container With Most Water

原文:http://www.cnblogs.com/lailailai/p/3715508.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!