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 };

 

posted on 2015-03-19 05:34  keepshuatishuati  阅读(129)  评论(0)    收藏  举报