Skip to content

Commit 3bb35ff

Browse files
authored
Update 1306-jump-game-iii.js
1 parent 56be66f commit 3bb35ff

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

1306-jump-game-iii.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,19 @@ function helper(arr, start, s) {
1515

1616
return helper(arr, start + arr[start], s) || helper(arr, start - arr[start], s)
1717
}
18+
19+
// another
20+
21+
/**
22+
* @param {number[]} arr
23+
* @param {number} start
24+
* @return {boolean}
25+
*/
26+
const canReach = function (A, i) {
27+
return (
28+
0 <= i &&
29+
i < A.length &&
30+
A[i] >= 0 &&
31+
(!(A[i] = -A[i]) || canReach(A, i + A[i]) || canReach(A, i - A[i]))
32+
)
33+
}

0 commit comments

Comments
 (0)