MCPcopy Create free account
hub / github.com/Hsinha11/Leetcode-solutions / canJump

Method canJump

55-jump-game/jump-game.java:4–14  ·  view source on GitHub ↗
(int[] nums)

Source from the content-addressed store, hash-verified

2
3class Solution {
4 public boolean canJump(int[] nums) {
5 int maxReach = 0;
6
7 for (int i = 0; i < nums.length; i++) {
8 if (i > maxReach) return false;
9 maxReach = Math.max(maxReach, i + nums[i]);
10 if (maxReach >= nums.length - 1) return true;
11 }
12
13 return true;
14 }
15}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected