My clean cpp solution very very easy to understand


  • 0
    X
    class Solution {
    public:
    		bool canJump(vector<int>& nums)
    		{
    			int max_jump = 0;
    			max_jump = std::max(max_jump, nums[0]);
    			for ( int i = 0; i<=max_jump; ++i )
    			{
    				if ( max_jump>=nums.size()-1 ) return true;
    				max_jump = std::max(max_jump, i+nums[i]);
    			}
    			return false;
    		}
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.