【Leetcode】 11 盛最多水的容器

tech2022-08-01  153

class Solution { public: int maxArea(vector<int>& height) { int maxArea = 0; int left = 0; int right = height.size() - 1; while(left < right) { maxArea = max(maxArea, min(height[left], height[right]) * (right - left)); if(height[left] < height[right]) left++; else right--; } return maxArea; } };

 

最新回复(0)