11. Container With Most Water

 

 

C++:

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

 

posted @ 2019-05-14 16:03  __Meng  阅读(110)  评论(0编辑  收藏  举报