Leetcode fifty-five questions (jumping games)

share picture

 class Solution {

public:
bool canJump(vector<int>& nums) {
int len=nums.size();
if(len==1)//Border border border!
return true ;

int max_bianjie=nums[0];//Set a boundary, initialized to 0+nums[0]
for(int i=0;i)
{
if(i+1+nums[i+1]>max_bianjie)//If i+1 is within the boundary, and i+1+nums[i+1]>max_bianjie, update the boundary
max_bianjie=i+1+nums[i+1];

if(max_bianjie>=len-1)< span style="color: #008000;">//If the border overflows, return true
return true ;
}
return false;
}
};

Analysis:

The hand feel is still very poor.

class Solution {

public:
bool canJump(vector<int>& nums) {
int len=nums.size();
if(len==1)//Border border border!
return true ;

int max_bianjie=nums[0];//Set a boundary, initialized to 0+nums[0]
for(int i=0;i)
{
if(i+1+nums[i+1]>max_bianjie)//If i+1 is within the boundary, and i+1+nums[i+1]>max_bianjie, update the boundary
max_bianjie=i+1+nums[i+1];

if(max_bianjie>=len-1)< span style="color: #008000;">//If the border overflows, return true
return true ;
}
return false;
}
};

Leave a Comment

Your email address will not be published.