Skip to content

Commit 32e1e4c

Browse files
committed
created files
1 parent 726459c commit 32e1e4c

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

coin-change/sungjinwi.py

Whitespace-only changes.

palindromic-substrings/sungjinwi.py

Whitespace-only changes.

word-search/sungjinwi.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
class Solution:
2+
def exist(self, board: List[List[str]], word: str) -> bool:
3+
visit = {}
4+
row = len(board)
5+
col = len(board[0])
6+
7+
def dfs(m : int, n : int, seq : str) :
8+
if visit[m, n] :
9+
return
10+
if not word.startswith(seq + board[m][n]) :
11+
return
12+
visit[(m, n)] = 1
13+
seq += board[m][n]
14+
if seq == word :
15+
return
16+
if m > 0 :
17+
if (dfs()) :
18+
return True
19+
if down :
20+
dfs()
21+
if left :
22+
dfs()
23+
if right :
24+
dfs()
25+
visit(m, n) = 0
26+
seq = seq[:len(seq)-1]
27+
28+
29+
while m in range(row) :
30+
while n in range(col) :
31+
if dfs(m, n, "") :
32+
return True
33+
visit.clear()
34+
return False

0 commit comments

Comments
 (0)