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