File tree 2 files changed +41
-1
lines changed
2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,219 LeetCode solutions in JavaScript
1
+ # 1,220 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
988
988
1302|[ Deepest Leaves Sum] ( ./solutions/1302-deepest-leaves-sum.js ) |Medium|
989
989
1304|[ Find N Unique Integers Sum up to Zero] ( ./solutions/1304-find-n-unique-integers-sum-up-to-zero.js ) |Easy|
990
990
1305|[ All Elements in Two Binary Search Trees] ( ./solutions/1305-all-elements-in-two-binary-search-trees.js ) |Medium|
991
+ 1306|[ Jump Game III] ( ./solutions/1306-jump-game-iii.js ) |Medium|
991
992
1309|[ Decrypt String from Alphabet to Integer Mapping] ( ./solutions/1309-decrypt-string-from-alphabet-to-integer-mapping.js ) |Easy|
992
993
1313|[ Decompress Run-Length Encoded List] ( ./solutions/1313-decompress-run-length-encoded-list.js ) |Easy|
993
994
1317|[ Convert Integer to the Sum of Two No-Zero Integers] ( ./solutions/1317-convert-integer-to-the-sum-of-two-no-zero-integers.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 1306. Jump Game III
3
+ * https://leetcode.com/problems/jump-game-iii/
4
+ * Difficulty: Medium
5
+ *
6
+ * Given an array of non-negative integers arr, you are initially positioned at start index of
7
+ * the array. When you are at index i, you can jump to i + arr[i] or i - arr[i], check if you
8
+ * can reach any index with value 0.
9
+ *
10
+ * Notice that you can not jump outside of the array at any time.
11
+ */
12
+
13
+ /**
14
+ * @param {number[] } arr
15
+ * @param {number } start
16
+ * @return {boolean }
17
+ */
18
+ var canReach = function ( arr , start ) {
19
+ const visited = new Set ( ) ;
20
+ const queue = [ start ] ;
21
+
22
+ while ( queue . length ) {
23
+ const current = queue . shift ( ) ;
24
+
25
+ if ( arr [ current ] === 0 ) return true ;
26
+ if ( visited . has ( current ) ) continue ;
27
+
28
+ visited . add ( current ) ;
29
+
30
+ const jump = arr [ current ] ;
31
+ const nextRight = current + jump ;
32
+ const nextLeft = current - jump ;
33
+
34
+ if ( nextRight < arr . length ) queue . push ( nextRight ) ;
35
+ if ( nextLeft >= 0 ) queue . push ( nextLeft ) ;
36
+ }
37
+
38
+ return false ;
39
+ } ;
You can’t perform that action at this time.
0 commit comments