File tree Expand file tree Collapse file tree 3 files changed +61
-0
lines changed
solution/1300-1399/1306.Jump Game III Expand file tree Collapse file tree 3 files changed +61
-0
lines changed Original file line number Diff line number Diff line change @@ -164,6 +164,28 @@ func canReach(arr []int, start int) bool {
164
164
}
165
165
```
166
166
167
+ ### ** TypeScript**
168
+
169
+ ``` ts
170
+ function canReach(arr : number [], start : number ): boolean {
171
+ const q: number [] = [start ];
172
+ while (q .length ) {
173
+ const i: number = q .shift ()! ;
174
+ if (arr [i ] === 0 ) {
175
+ return true ;
176
+ }
177
+ const x: number = arr [i ];
178
+ arr [i ] = - 1 ;
179
+ for (const j of [i + x , i - x ]) {
180
+ if (j >= 0 && j < arr .length && arr [j ] !== - 1 ) {
181
+ q .push (j );
182
+ }
183
+ }
184
+ }
185
+ return false ;
186
+ }
187
+ ```
188
+
167
189
### ** ...**
168
190
169
191
```
Original file line number Diff line number Diff line change @@ -145,6 +145,28 @@ func canReach(arr []int, start int) bool {
145
145
}
146
146
```
147
147
148
+ ### ** TypeScript**
149
+
150
+ ``` ts
151
+ function canReach(arr : number [], start : number ): boolean {
152
+ const q: number [] = [start ];
153
+ while (q .length ) {
154
+ const i: number = q .shift ()! ;
155
+ if (arr [i ] === 0 ) {
156
+ return true ;
157
+ }
158
+ const x: number = arr [i ];
159
+ arr [i ] = - 1 ;
160
+ for (const j of [i + x , i - x ]) {
161
+ if (j >= 0 && j < arr .length && arr [j ] !== - 1 ) {
162
+ q .push (j );
163
+ }
164
+ }
165
+ }
166
+ return false ;
167
+ }
168
+ ```
169
+
148
170
### ** ...**
149
171
150
172
```
Original file line number Diff line number Diff line change
1
+ function canReach ( arr : number [ ] , start : number ) : boolean {
2
+ const q : number [ ] = [ start ] ;
3
+ while ( q . length ) {
4
+ const i : number = q . shift ( ) ! ;
5
+ if ( arr [ i ] === 0 ) {
6
+ return true ;
7
+ }
8
+ const x : number = arr [ i ] ;
9
+ arr [ i ] = - 1 ;
10
+ for ( const j of [ i + x , i - x ] ) {
11
+ if ( j >= 0 && j < arr . length && arr [ j ] !== - 1 ) {
12
+ q . push ( j ) ;
13
+ }
14
+ }
15
+ }
16
+ return false ;
17
+ }
You can’t perform that action at this time.
0 commit comments