Skip to content

Commit

Permalink
Merge pull request #884 from hlee2052/main
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Nov 12, 2023
2 parents 74ff7fa + 103180f commit 852a832
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Solution:
def maxUniqueSplit(self, s: str) -> int:

def dfs(i):

res = 0

if i >= len(s):
return 0

for j in range(i + 1, len(s) + 1):
tmp = s[i:j]
if tmp not in visited:
visited.add(tmp)
res = max(res, 1 + dfs(j))
visited.remove(tmp)

return res

visited = set()
return dfs(0)
20 changes: 20 additions & 0 deletions HyunWooLee/week9 - backtracking/2023-11-12-77_Combinations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Solution:

def combine(self, n: int, k: int) -> List[List[int]]:

def dfs(start, arr):
if start > n + 1:
return

if len(arr) == k:
result.append(arr[:])
return

for i in range(start, n + 1):
arr.append(i)
dfs(i + 1, arr)
arr.pop()

result = []
dfs(1, [])
return result
39 changes: 39 additions & 0 deletions HyunWooLee/week9 - backtracking/2023-11-12-79_word_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
class Solution(object):
def exist(self, board, word):
"""
:type board: List[List[str]]
:type word: str
:rtype: bool
"""

def dfs(row, col, curr_len):
if row < 0 or len(board) <= row or col < 0 or len(board[0]) <= col:
return False

curr_word = word[len(word) - curr_len]

if board[row][col] != curr_word:
return False

if curr_len == 1:
return True

prev = board[row][col]

board[row][col] = None

top = dfs(row - 1, col, curr_len - 1)
down = dfs(row + 1, col, curr_len - 1)
left = dfs(row, col - 1, curr_len - 1)
right = dfs(row, col + 1, curr_len - 1)

board[row][col] = prev

return top or down or left or right

for i in range(len(board)):
for j in range(len(board[0])):
if dfs(i, j, len(word)):
return True

return False

0 comments on commit 852a832

Please sign in to comment.