首页 > 其他 > 详细

LeetCode – Refresh – Container With Most Water

时间:2015-03-19 06:18:51      阅读:311      评论:0      收藏:0      [点我收藏+]

The minimum height controls the volumns. So let two runner at two ends start to scan the array.

 

 1 class Solution {
 2 public:
 3     int maxArea(vector<int> &height) {
 4         int start = 0, end = height.size()-1, result = 0;
 5         while (start < end) {
 6             result = max(result, min(height[start], height[end]) * (end - start));
 7             if (height[start] < height[end]) {
 8                 start++;
 9             } else {
10                 end--;
11             }
12         }
13         return result;
14     }
15 };

 

LeetCode – Refresh – Container With Most Water

原文:http://www.cnblogs.com/shuashuashua/p/4349277.html

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