11. Container With Most Water

题目描述:

https://leetcode.com/problems/container-with-most-water/

解决方法:

https://leetcode.com/problems/container-with-most-water/solution/

mycode(c++):

approach1:brute

class Solution {
public:
    int maxArea(vector& height) {
        int max_area = 0;
        for( int i = 0;i max_area)
                    max_area = area;
            }
        return max_area;
    }
};

approach2:(two pointer)

class Solution {
public:
    int maxArea(vector& height) {
        int max_area = 0;int l = 0 ,r = height.size()-1;
        while(l < r ){
            max_area = max(max_area,min(height.at(r),height.at(l))*(r-l));
            if(height.at(l)

心得:

主要还是要具体问题具体分析,根据实际问题分析。

你可能感兴趣的:(11. Container With Most Water)