Leetcode: 11. 盛最多水的容器 C语言实现 2020.2.10

Leetcode: 11. 盛最多水的容器 C语言实现 2020.2.10_第1张图片

 

int maxArea(int* height, int heightSize){
    int max = -1;
    int area;
    for(int i = 0; i < heightSize; i++){
        //printf("%d ", height[i]);
        for(int j = i+1; j < heightSize; j++){
            area = (j-i)*(height[i] max){
                max = area;
            }
        }
    }
    return max;
}

 

 

int maxArea(int* height, int heightSize){
    int i = 0;
    int j = heightSize-1;
    int max = 0;
    int area;

    while(i < j){
        area = (j-i)*(height[i] max) ? area : max;
        if(height[i] <= height[j]){
            i+=1;
        }else{
            j-=1;
        }
    }

    return max;
}

 

你可能感兴趣的:(LeetCode)