欢迎光临
我们一直在努力

11. 盛最多水的容器c

int maxArea(int* height, int heightSize) {
    int max=0;
    int head=0,tail=heightSize-1;
    while(head<tail){
        int sum;
        if(height[head]<height[tail]){
            sum=height[head]*(tail-head);
            head++;
        }else if(height[head]>height[tail]){
            sum=height[tail]*(tail-head);
            tail--;
        }else{
            sum=height[head]*(tail-head);
            head++;
            tail--;
        }
        if(max< sum)  max=sum;       
    }
    return max;
}

双指针

未经允许不得转载:大有博文 » 11. 盛最多水的容器c
分享到: 更多 (0)

大前端WP主题 更专业 更方便

联系我们联系我们