forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_11.cpp
More file actions
26 lines (20 loc) · 704 Bytes
/
_11.cpp
File metadata and controls
26 lines (20 loc) · 704 Bytes
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
// container-with-most-water
// Problem Statement: https://leetcode.com/problems/container-with-most-water
#include<bits/stdc++.h>
using namespace std;
class Solution {
public:
int maxArea(vector<int>& height) {
if(height.size() < 1)
return 0;
int left = 0;
int right = height.size() - 1;
int result = 0;
while(left < right){
int area = (height[left] < height[right]) ? (height[left] * (right - left)) : (height[right] * (right -left));
result = (area > result) ? area : result;
(height[left] < height[right]) ? left++ : right--;
}
return result;
}
};