container with te most water
1 class Solution { 2 public: 3 int maxArea(vector<int> &height) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 if( height.size() <= 1 ) return 0; 7 int left = 0,right = height.size() - 1; 8 int max_size = 0; 9 while( left < right ) 10 { 11 max_size = max( max_size, min(height[left], height[right])*(right - left)); 12 if( height[left] < height[right] ) 13 left ++; 14 else if ( height[left] > height[right] ) 15 right --; 16 else 17 { 18 left ++ ; 19 right --; 20 } 21 22 } 23 return max_size; 24 } 25 };
posted on 2013-09-04 09:54 jumping_grass 阅读(145) 评论(0) 收藏 举报
浙公网安备 33010602011771号