Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions word-search/printjin-gmailcom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from typing import List

class Solution:
def exist(self, board, word):
m, n = len(board), len(board[0])
def dfs(x, y, index):
if index == len(word):
return True
if x < 0 or x >= m or y < 0 or y >= n or board[x][y] != word[index]:
return False
temp = board[x][y]
board[x][y] = '#'
found = (
dfs(x + 1, y, index + 1) or dfs(x - 1, y, index + 1) or dfs(x, y + 1, index + 1) or dfs(x, y - 1, index + 1)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

한줄에 or 로 하니 보기 더 좋네요

board[x][y] = temp
return found

for i in range(m):
for j in range(n):
if dfs(i, j, 0):
return True
return False