美文网首页
11. Container With Most Water

11. Container With Most Water

作者: FlynnLWang | 来源:发表于2016-10-18 10:33 被阅读0次

    Question Description

    Screen Shot 2016-10-17 at 22.29.35.png

    My Code

    public class Solution {
        public int maxArea(int[] height) {
            int result = 0;
            int i = 0, j = height.length - 1;
            while (i < j) {
                int x = j - i; 
                int y = Math.min(height[i], height[j]);
                int area = x * y;
                result = area > result ? area : result;
                if (height[i] < height[j]) i++;
                else j--;
            }
            return result;
        }
    }
    

    Test Result

    Screen Shot 2016-10-17 at 22.29.59.png

    相关文章

      网友评论

          本文标题:11. Container With Most Water

          本文链接:https://www.haomeiwen.com/subject/rqazyttx.html