题目描述 方法一 bool canJump ( vector int nums ) { int k = 0 ; for ( int i = 0 ; i nums . size (); i + + ) { if ( i k ) return false ; k = max ( k , i + nums [ i ]); #k为当前能向前跳的最大距离 } return true ; } 参考链接
题目描述
方法一
bool canJump(vector<int>& nums)
{
int k = 0;
for (int i = 0; i < nums.size(); i++)
{
if (i > k) return false;
k = max(k, i + nums[i]); #k为当前能向前跳的最大距离
}
return true;
}
参考链接
https://leetcode-cn.com/problems/jump-game/solution/55-by-ikaruga/
https://leetcode-cn.com/problems/jump-game/solution/tiao-yue-you-xi-by-leetcode/