We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 15c99cd commit cd23cc2Copy full SHA for cd23cc2
jump-game/forest000014.java
@@ -0,0 +1,24 @@
1
+/*
2
+# Time Complexity: O(n)
3
+# Space Complexity: O(n)
4
+*/
5
+
6
+class Solution {
7
+ public boolean canJump(int[] nums) {
8
+ int n = nums.length;
9
+ boolean[] dp = new boolean[n];
10
11
+ dp[0] = true;
12
13
+ for (int i = 0; i < n; i++) {
14
+ if (!dp[i]) return false;
15
+ int j = Math.min(n - 1, i + nums[i]);
16
+ for (; j >= i + 1; j--) {
17
+ if (dp[j]) break;
18
+ dp[j] = true;
19
+ }
20
21
22
+ return true;
23
24
+}
0 commit comments