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 dac7287 commit 97d6228Copy full SHA for 97d6228
contest/src/main/java/com/github/contest/dp/DpAlternativeSolution.kt
@@ -0,0 +1,23 @@
1
+package com.github.contest.dp
2
+
3
+/**
4
+ * 55. Jump Game
5
+ * Alternative Solution
6
+ * Recursion Approach
7
+ */
8
9
+fun canJumpAltSolution(nums: IntArray): Boolean = solve(nums, 0)
10
11
+private fun solve(nums: IntArray, index: Int): Boolean {
12
+ if (index >= nums.size - 1) return true
13
+ if (nums[index] == 0 && index < nums.size - 1) return false
14
15
+ var step = nums[index]
16
17
+ while (step != 0) {
18
+ if (solve(nums, index + step)) return true
19
+ step--
20
+ }
21
22
+ return false
23
+}
0 commit comments