11. Container With Most Water

amazingggggg

https://discuss.leetcode.com/topic/29962/for-someone-who-is-not-so-clear-on-this-question

https://discuss.leetcode.com/topic/14940/simple-and-clear-proof-explanation

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

results matching ""

    No results matching ""