Skip to content

Commit 46364b1

Browse files
Merge pull request #1840 from CodingTestStudy2/황은지
[황은지] Day17
2 parents 753ed64 + e7ffb16 commit 46364b1

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* @param {number} m
3+
* @param {number} n
4+
* @param {number} maxMove
5+
* @param {number} startRow
6+
* @param {number} startColumn
7+
* @return {number}
8+
*/
9+
var findPaths = function (m, n, maxMove, startRow, startColumn) {
10+
const queue = [[startRow, startColumn]];
11+
let head = 0;
12+
let count = 0;
13+
const dir = [
14+
[0, 1],
15+
[0, -1],
16+
[1, 0],
17+
[-1, 0],
18+
];
19+
20+
for (let i = 0; i < maxMove; i++) {
21+
const size = queue.length - head;
22+
for (let k = 0; k < size; k++) {
23+
const [currR, currC] = queue[head++];
24+
for (let j = 0; j < 4; j++) {
25+
const nextR = currR + dir[j][0];
26+
const nextC = currC + dir[j][1];
27+
if (nextR < 0 || nextR >= m || nextC < 0 || nextC >= n) count++;
28+
else queue.push([nextR, nextC]);
29+
}
30+
}
31+
}
32+
33+
return count % (Math.pow(10, 9) + 7);
34+
};

0 commit comments

Comments
 (0)