11
class Solution { public int maxArea(int[] nums) { int area = 0; int left = 0; int right = nums.length - 1; while(left <= right) { area = Math.max(area, (right - left) * Math.min(nums[left], nums[right])); if(nums[left] >= nums[right]) { int cur = nums[right]; while(left <= right && nums[right] <= cur) right--; } else { int cur = nums[left]; while(left <= right && nums[left] <= cur) left++; } } return area; } }
posted on 2023-09-09 22:07 zhouzhou0615 阅读(9) 评论(0) 编辑 收藏 举报