Short C++ implementation.

  • 3

    Thanks the post from top voted solution.

    Here is the AC c++ implementation

       class Solution {
            bool canJump(vector<int>& nums) {
                int n=nums.size();
                int i=0, reach=0;
                for(; i<n && i<=reach; i++)
                    reach=max(reach, i+nums[i]);
                return reach+1>=n;

Log in to reply

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