Skip to content

Commit 7c936dd

Browse files
authored
Make spacing consistent
1 parent 0723d44 commit 7c936dd

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

javascript/0909-snakes-and-ladders.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,26 @@
55
var snakesAndLadders = function(board) {
66
let n = board.length;
77
let set = new Set();
8-
let getPos = (pos) =>{
9-
let row = Math.floor((pos-1) / n)
10-
let col = (pos-1) % n
8+
let getPos = (pos) => {
9+
let row = Math.floor((pos - 1) / n)
10+
let col = (pos - 1) % n
1111
col = row % 2 == 1 ? n - 1 - col : col;
1212
row = n - 1 - row;
13-
return [row,col]
13+
return [row, col]
1414
}
15-
let q = [[1,0]]
16-
while(q.length>0){
17-
[pos,moves] = q.shift();
18-
for(let i =1; i<7; i++){
19-
let newPos = i+pos;
20-
let [r,c] = getPos(newPos);
21-
if(board[r][c] != -1 ) newPos = board[r][c]
22-
if(newPos == n*n) return moves+1;
23-
if(!set.has(newPos)){
15+
let q = [[1, 0]]
16+
while (q.length > 0){
17+
[pos, moves] = q.shift();
18+
for (let i = 1; i < 7; i++){
19+
let newPos = i + pos;
20+
let [r, c] = getPos(newPos);
21+
if (board[r][c] != -1 ) newPos = board[r][c]
22+
if (newPos == n * n) return moves + 1;
23+
if (!set.has(newPos)) {
2424
set.add(newPos)
25-
q.push([newPos,moves+1])
25+
q.push([newPos, moves + 1])
2626
}
2727
}
2828
}
2929
return -1
30-
};
30+
};

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy