Skip to content

Commit 7f02ce6

Browse files
committed
word-search 방문 체크 로직 위치 수정
1 parent 93a6ebf commit 7f02ce6

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

word-search/jdalma.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ class `word-search` {
1717
private fun usingBacktracking(board: Array<CharArray>, word: String): Boolean {
1818
fun dfs(board: Array<CharArray>, visited: Array<BooleanArray>, word: String, position: Position, index: Int): Boolean {
1919
if (index == word.length) return true
20-
visited[position.x][position.y] = true
21-
2220
for (move in MOVES) {
2321
val next = position + move
2422
if (next.isNotOutOfIndexed(board) && !visited[next.x][next.y] && board[next.x][next.y] == word[index]) {
@@ -36,6 +34,7 @@ class `word-search` {
3634

3735
for (x in board.indices) {
3836
for (y in board[x].indices) {
37+
visited[x][y] = true
3938
if (board[x][y] == word[0] && dfs(board, visited, word, Position(x,y), 1)) {
4039
return true
4140
}

0 commit comments

Comments
 (0)