C++ smiple and easy to understand O(n) time 4 lines


  • 13
    K
    class Solution {
    public:
    	bool canJump(vector<int>& nums) {
    		int truepos=nums.size()-1;//the lowest starting point that you can reach the end 
    		for(int i=nums.size()-2;i>=0;i--)
    			truepos=(i+nums[i])>=truepos?i:truepos;
    		return(truepos==0);	
    	}
    };

  • 0
    V

    What a brilliant and concise solution! Thank you.


Log in to reply
 

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