leetcode中提升代码IO速度

在leetcode第11题看到一个题解,添加到代码前面,大幅缩减runtime

代码为:

1
2
3
4
5
static int speedup=[](){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
return 0;
}();

leetcode11题解

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
static int speedup=[](){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
return 0;
}();
class Solution
{
public:
int maxArea(vector<int> &height)
{
int i = 0, j = height.size() - 1, water = 0;
while (i < j)
{
int h = min(height[i], height[j]);
water = max(water, (j - i) * h);
while (height[i] <= h && i < j)
i++;
while (height[j] <= h && i < j)
j--;
}
return water;
}
};
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.

扫一扫,分享到微信

微信分享二维码
  • Copyrights © 2015-2020 John Doe
  • Visitors: | Views:

请我喝杯咖啡吧~

支付宝
微信