11 Container With Most Water

我会带着你远行 2022-08-09 02:15 107阅读 0赞
  1. public class No11 {
  2. public static void main(String[] args) {
  3. int[] height = { 3, 4, 5 ,3};
  4. System.out.println(maxArea(height));
  5. }
  6. public static int maxArea(int[] height) {
  7. int left=0;
  8. int right=height.length-1;
  9. int max=0;
  10. int size=0;
  11. while(left<right){
  12. size=(right-left)*Math.min(height[left], height[right]);
  13. max=max>size?max:size;
  14. if(height[left]>height[right])
  15. right--;
  16. else
  17. left++;
  18. }
  19. return max;
  20. }
  21. }

发表评论

表情:
评论列表 (有 0 条评论,107人围观)

还没有评论,来说两句吧...

相关阅读