Skip to content

Commit 36daa2e

Browse files
committed
11
1 parent dd8aadd commit 36daa2e

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

11_container_with_most_water.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include "test.h"
2+
3+
4+
class Solution
5+
{
6+
public:
7+
int maxArea(const vector<int>& height)
8+
{
9+
uint32_t left = 0;
10+
uint32_t right = height.size() - 1;
11+
uint32_t theMaxArea = 0;
12+
while (left < right)
13+
{
14+
uint32_t width = right - left;
15+
uint32_t minHeight = height[left] < height[right] ? height[left++] : height[right--];
16+
uint32_t area = minHeight * width;
17+
if (theMaxArea < area)
18+
theMaxArea = area;
19+
}
20+
21+
return theMaxArea;
22+
}
23+
};
24+
25+
26+
//本次好奇, 看了一下那些运行时间最短的提交
27+
//发现一个搞竞赛的人用来刷运行速度的奇技淫巧,
28+
//大概是干掉标准的iostream的同步保证,
29+
//提交时带上这个, 就是效率第一梯队打败100%的玩家了,
30+
//玩竞赛的人好无聊的说~~
31+
static int x = []()
32+
{
33+
std::ios::sync_with_stdio(false);
34+
cin.tie(NULL);
35+
return 0;
36+
}();
37+
38+
39+
int main()
40+
{
41+
Solution s;
42+
cout
43+
<< s.maxArea({1,8,6,2,5,4,8,3,7}) << ", "
44+
<< s.maxArea({1,2}) << ", "
45+
<< endl;
46+
}

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ targets = \
99
8_string_to_interger.exec\
1010
9_palindrome_number.exec\
1111
10_regular_expression_matching.exec\
12+
11_container_with_most_water.exec\
1213

1314

1415
CC = g++

0 commit comments

Comments
 (0)