码迷,mamicode.com
首页 > 其他好文 > 详细

LeetCode – Refresh – Container With Most Water

时间:2015-03-19 06:21:12      阅读:147      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!