题解 | #跳跃游戏(一)#
跳跃游戏(一)
https://www.nowcoder.com/practice/07484f4377344d3590045a095910992b
贪心算法
#include <iostream> using namespace std; const int N = 2 * 100010; int a[N]; int main() { int n; cin >> n; for(int i = 0; i < n; i ++) cin >> a[i]; int maxReach = 0; int i; for(i = 0; i < n; i ++){ if(i > maxReach){ cout << "false" << endl; break; } maxReach = max(maxReach, i + a[i]); } if(i >= n) cout << "true" << endl; return 0; }