Skip to content

Commit 56be66f

Browse files
authored
Create 1306-jump-game-iii.js
1 parent 756aec5 commit 56be66f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

1306-jump-game-iii.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @param {number[]} arr
3+
* @param {number} start
4+
* @return {boolean}
5+
*/
6+
const canReach = function(arr, start) {
7+
const s = new Set()
8+
return helper(arr, start, s)
9+
};
10+
11+
function helper(arr, start, s) {
12+
if(start < 0 || start >= arr.length || s.has(start)) return false
13+
s.add(start)
14+
if(arr[start] === 0) return true
15+
16+
return helper(arr, start + arr[start], s) || helper(arr, start - arr[start], s)
17+
}

0 commit comments

Comments
 (0)