-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11.cpp
34 lines (33 loc) · 774 Bytes
/
11.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//
// 11.cpp
// leetcode
//
// Created by R Z on 2018/1/29.
// Copyright © 2018年 R Z. All rights reserved.
//
#include <stdio.h>
#include <vector>
using namespace std;
class Solution {
public:
int maxArea(vector<int>& height) {
int len = height.size();
if(len<2) return 0;
int lo=0, hi=len-1, container=0;
while(lo<hi){
if(height[lo]<height[hi]){
if(height[lo]*(hi-lo)>container){
container=height[lo]*(hi-lo);
}
lo++;
}
else{
if(height[hi]*(hi-lo)>container){
container=height[hi]*(hi-lo);
}
hi--;
}
}
return container;
}
};