-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP55.cpp
More file actions
39 lines (35 loc) · 741 Bytes
/
P55.cpp
File metadata and controls
39 lines (35 loc) · 741 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
36
37
38
39
#include<algorithm>
#include<vector>
#include<iostream>
#include<string>
#include<stack>
using namespace std;
class Solution {
public:
bool canJump(vector<int>& nums) {
int far,i,dest;
if (nums.empty()) return false;
dest=nums.size()-1;
i=0;
far=0;
while (i<=far && far<dest) {
if (i+nums[i]>far) far=i+nums[i];
i++;
}
return far>=dest;
}
};
static const auto io_sync_off = []()
{
// turn off sync
std::ios::sync_with_stdio(false);
// untie in/out streams
std::cin.tie(nullptr);
return nullptr;
}();
int main() {
vector<int> a={2,3,1,1,4};
auto res = Solution().canJump(a);
cout << res <<endl;
return 0;
}