【数组】11. 盛最多水的容器
题目:

解答:

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

浙公网安备 33010602011771号