Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
26 changes: 26 additions & 0 deletions coin-change/daiyongg-kim.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Solution:
def coinChange(self, coins: List[int], amount: int) -> int:
if amount == 0:
return 0

level = [0]
visited = {0}
count = 0

while level:
count += 1
next_level = []

for current_amount in level:
for coin in coins:
new_amount = current_amount + coin

if new_amount == amount:
return count

if new_amount < amount and new_amount not in visited:
visited.add(new_amount)
next_level.append(new_amount)
level = next_level

return -1
14 changes: 14 additions & 0 deletions find-minimum-in-rotated-sorted-array/daiyongg-kim.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Solution:
def findMin(self, nums: List[int]) -> int:
#constraint complexity: O(log n)
left = 0
right = len(nums) - 1

while left < right:
mid = (left + right) // 2

if nums[mid] < nums[right]:
right = mid
else:
left = mid + 1
return nums[left]
27 changes: 27 additions & 0 deletions maximum-depth-of-binary-tree/daiyongg-kim.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class Solution:

def maxDepth(self, root: Optional[TreeNode]) -> int:
if not root:
return 0
queue = deque([root])
depth = 0

while queue:
depth += 1
print(len(queue))
for _ in range(len(queue)):
node = queue.popleft()
if node.left:
queue.append(node.left)
if node.right:
queue.append(node.right)
return depth


# if not root:
# return 0

# left_depth = self.maxDepth(root.left)
# right_depth = self.maxDepth(root.right)

# return max(left_depth, right_depth) + 1
38 changes: 38 additions & 0 deletions merge-two-sorted-lists/daiyongg-kim.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def mergeTwoLists(self, list1: Optional[ListNode], list2: Optional[ListNode]) -> Optional[ListNode]:
if list1 is None:
return list2
if list2 is None:
return list1

if list1.val < list2.val:
list1.next = self.mergeTwoLists(list1.next, list2)
return list1
else:
list2.next = self.mergeTwoLists(list1, list2.next)
return list2

# class Solution:
# def mergeTwoLists(self, list1: Optional[ListNode], list2: Optional[ListNode]) -> Optional[ListNode]:
# result = ListNode(-1)
# dummy = result
# while list1 and list2:
# if list1.val < list2.val:
# dummy.next = list1
# list1 = list1.next
# else:
# dummy.next = list2
# list2 = list2.next
# dummy = dummy.next

# if list1:
# dummy.next = list1
# else:
# dummy.next = list2

# return result.next
28 changes: 28 additions & 0 deletions word-search/daiyongg-kim.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class Solution:

def exist(self, board: List[List[str]], word: str) -> bool:
row = len(board)
col = len(board[0])

def dfs(i: int, j: int, k: int):
if k == len(word):
return True

if i < 0 or i >= row or j < 0 or j >= col or board[i][j] != word[k]:
return False

current = board[i][j]
board[i][j] = ''

if dfs(i-1, j, k+1) or dfs(i+1, j, k+1) or dfs(i, j-1, k+1) or dfs(i, j+1, k+1):
return True

board[i][j] = current
return False

for i in range(row):
for j in range(col):
if dfs(i, j, 0):
return True

return False