From e7ffb16f416dff5ce67de5b6a6b2c1d7a7990975 Mon Sep 17 00:00:00 2001 From: dmswl6310 Date: Sat, 15 Aug 2026 22:44:41 +0900 Subject: [PATCH] 0815 --- .../576. Out of Boundary Paths.js" | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 "leetcode3/\355\231\251\354\235\200\354\247\200/576. Out of Boundary Paths.js" diff --git "a/leetcode3/\355\231\251\354\235\200\354\247\200/576. Out of Boundary Paths.js" "b/leetcode3/\355\231\251\354\235\200\354\247\200/576. Out of Boundary Paths.js" new file mode 100644 index 00000000..6e717011 --- /dev/null +++ "b/leetcode3/\355\231\251\354\235\200\354\247\200/576. Out of Boundary Paths.js" @@ -0,0 +1,34 @@ +/** + * @param {number} m + * @param {number} n + * @param {number} maxMove + * @param {number} startRow + * @param {number} startColumn + * @return {number} + */ +var findPaths = function (m, n, maxMove, startRow, startColumn) { + const queue = [[startRow, startColumn]]; + let head = 0; + let count = 0; + const dir = [ + [0, 1], + [0, -1], + [1, 0], + [-1, 0], + ]; + + for (let i = 0; i < maxMove; i++) { + const size = queue.length - head; + for (let k = 0; k < size; k++) { + const [currR, currC] = queue[head++]; + for (let j = 0; j < 4; j++) { + const nextR = currR + dir[j][0]; + const nextC = currC + dir[j][1]; + if (nextR < 0 || nextR >= m || nextC < 0 || nextC >= n) count++; + else queue.push([nextR, nextC]); + } + } + } + + return count % (Math.pow(10, 9) + 7); +};