-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"use strict"; | ||
|
||
function solution(board) { | ||
let answer = 0; | ||
let dx = [-1, 0, 1, 0]; | ||
let dy = [0, 1, 0, -1]; | ||
|
||
function dfs(x, y) { | ||
if (x === 6 && y === 6) { | ||
answer++; | ||
} else { | ||
for (let i = 0; i < 4; i++) { | ||
let nx = x + dx[i]; | ||
let ny = y + dy[i]; | ||
|
||
if (nx >= 0 && nx <= 6 && ny >= 0 && ny <= 6 && board[nx][ny] === 0) { | ||
board[nx][ny] = 1; | ||
dfs(nx, ny); | ||
board[nx][ny] = 0; // back했으니 | ||
} | ||
} | ||
} | ||
} | ||
board[0][0] = 1; | ||
dfs(0, 0); | ||
return answer; | ||
} | ||
|
||
let arr = [ | ||
[0, 0, 0, 0, 0, 0, 0], | ||
[0, 1, 1, 1, 1, 1, 0], | ||
[0, 0, 0, 1, 0, 0, 0], | ||
[1, 1, 0, 1, 0, 1, 1], | ||
[1, 1, 0, 0, 0, 0, 1], | ||
[1, 1, 0, 1, 1, 0, 0], | ||
[1, 0, 0, 0, 0, 0, 0], | ||
]; | ||
|
||
console.log(solution(arr)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters