Easy C# O(n) solution


  • 1
    N
    public class Solution {
        int maxReach = 0;
        public bool CanJump(int[] nums) {
            int i = 0;
            while(i < nums.Length && i <= maxReach)
            {
                if(maxReach >= nums.Length-1 || i == nums.Length)
                {
                    return true;
                }
                
                if(maxReach < nums[i] + i)
                {
                    maxReach = nums[i] + i;
                }
               
               i++;
            }
            
            return false;
        }
    }

Log in to reply
 

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