Skip to content

Commit 51dcae7

Browse files
committed
feat: update solutions to lc problem: No.1306
1 parent 06e5f78 commit 51dcae7

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

solution/1300-1399/1306.Jump Game III/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,28 @@ func canReach(arr []int, start int) bool {
164164
}
165165
```
166166

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+
167189
### **...**
168190

169191
```

solution/1300-1399/1306.Jump Game III/README_EN.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,28 @@ func canReach(arr []int, start int) bool {
145145
}
146146
```
147147

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+
148170
### **...**
149171

150172
```
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
}

0 commit comments

Comments
 (0)