Skip to content

Commit 0852003

Browse files
authored
Update dependencies
1 parent 4e53c8a commit 0852003

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

minimum-sideway-jumps/index.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
function minSideJumps(obstacles: number[]): number {
2-
const n = obstacles.length
3-
let ans = 0
4-
let cur = 2 // 记录青蛙当前所在的跑道
5-
for (let i = 0; i < n; i++) {
6-
if (obstacles[i + 1] !== cur) continue
7-
// 记录另外两条跑道
8-
const other = (cur + 1) % 3 || 3
9-
const another = (cur + 2) % 3 || 3
2+
const n = obstacles.length;
3+
let ans = 0;
4+
let cur = 2; // 记录青蛙当前所在的跑道
5+
for (let i = 0; i < n; i++) {
6+
if (obstacles[i + 1] !== cur) continue;
7+
// 记录另外两条跑道
8+
const other = (cur + 1) % 3 || 3;
9+
const another = (cur + 2) % 3 || 3;
1010

11-
// 求另两个跑道,下一个障碍物的位置
12-
let next = i
13-
while (next < n && obstacles[next] !== other) {
14-
next++
11+
// 求另两个跑道,下一个障碍物的位置
12+
let next = i;
13+
while (next < n && obstacles[next] !== other) {
14+
next++;
15+
}
16+
while (i < n && obstacles[i] !== another) {
17+
i++;
18+
}
19+
cur = next > i ? other : another;
20+
i = Math.max(next, i) - 2;
21+
ans++;
1522
}
16-
while (i < n && obstacles[i] !== another) {
17-
i++
18-
}
19-
cur = next > i ? other : another
20-
i = Math.max(next, i) - 2
21-
ans++
22-
}
23-
return ans
23+
return ans;
2424
}
25-
export default minSideJumps
25+
export default minSideJumps;

0 commit comments

Comments
 (0)