forked from liuyubobobo/Play-Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
35 lines (26 loc) · 715 Bytes
/
main.cpp
File metadata and controls
35 lines (26 loc) · 715 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
26
27
28
29
30
31
32
33
34
35
/// Source : https://leetcode.com/problems/container-with-most-water/
/// Author : liuyubobobo
/// Time : 2018-08-13
#include <iostream>
#include <vector>
#include <cassert>
using namespace std;
/// Brute Force
/// Time Complexity: O(n^2)
/// Space Complexity: O(1)
class Solution {
public:
int maxArea(vector<int>& height) {
assert(height.size() >= 2);
int area = 0;
for(int i = 0 ; i < height.size() ; i ++)
for(int j = i + 1; j < height.size() ; j ++)
area = max(area , min(height[i], height[j]) * (j - i));
return area;
}
};
int main() {
vector<int> nums1 = {1, 1};
cout << Solution().maxArea(nums1) << endl;
return 0;
}