题解 | 跳跃游戏(一)
跳跃游戏(一)
https://www.nowcoder.com/practice/07484f4377344d3590045a095910992b
#include <bits/stdc++.h>
using namespace std;
/*
维护最远能到达的地方,如果有一个点不能被到达,那么这个点后面的也不会被到达,直接cout<<false
*/
const int N = 2e5 + 10;
int n,a[N];
int main(){
cin>>n;
for(int i = 1;i<=n;i++) cin>>a[i];
int now = 1;
for(int i = 1;i<=n;i++){
if(now<i) return cout<<"false",0;
now = max(now,i+a[i]);
}
cout<<"true";
return 0;
}
#牛客春招刷题训练营#https://www.nowcoder.com/discuss/727521113110073344
查看11道真题和解析