| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Generator
- Python Implementation
- DWG
- t1
- Convert Sorted List to Binary Search Tree
- 운영체제
- Substring with Concatenation of All Words
- 30. Substring with Concatenation of All Words
- kaggle
- 315. Count of Smaller Numbers After Self
- Python
- 밴픽
- 파이썬
- Regular Expression
- attribute
- Decorator
- 43. Multiply Strings
- data science
- Class
- Python Code
- 109. Convert Sorted List to Binary Search Tree
- 시바견
- 프로그래머스
- shiba
- 컴퓨터의 구조
- 715. Range Module
- LeetCode
- concurrency
- iterator
- Protocol
Archives
- Today
- Total
Scribbling
LeetCode: 79. Word Search 본문
class Solution:
def exist(self, board: List[List[str]], word: str) -> bool:
n, m = len(board), len(board[0])
for i in range(n):
for j in range(m):
if self.dfs(board, i, j, word, 0):
return True
return False
def dfs(self, board, y, x, word, k):
if k == len(word):
return True
if y < 0 or y >= len(board) or x < 0 or x >= len(board[0]) or board[y][x] == '@':
return False
char = word[k]
if board[y][x] != char:
return False
board[y][x] = '@'
dy, dx = [0, 1, 0, -1], [1, 0, -1, 0]
for d in range(4):
next_y, next_x = y + dy[d], x + dx[d]
if self.dfs(board, next_y, next_x, word, k+1):
return True
board[y][x] = char
return False'Computer Science > Coding Test' 카테고리의 다른 글
| LeetCode: 84. Largest Rectangle in Histogram (0) | 2021.10.04 |
|---|---|
| LeetCode: 85. Maximal Rectangle (0) | 2021.10.04 |
| LeetCode: 78. Subsets (0) | 2021.10.01 |
| LeetCode: 76. Minimum Window Substring (0) | 2021.09.30 |
| LeetCode: 77. Combinations (0) | 2021.09.28 |