House Robber III - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. BFS를 이용한 Level 별 탐색(실패) from collections import defaultdict, deque class Solution: def rob(self, root: TreeNode) -> int: dict1 = defaultdict(int) if not root: return 0 q = deque([(root, 0)]) while q: cur_node, cu..
Letter Combinations of a Phone Number - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. DFS class Solution(object): def letterCombinations(self, digits): dict1 = {2: ["a", "b", "c"], 3: ["d", "e", "f"], 4: ["g", "h", "i"], 5: ["j", "k", "l"], 6: ["m", "n", "o"], 7: ["p", "q", "r..
Decode String - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. Stack과 Dict을 이용한 풀이 from collections import deque class Solution: def decodeString(self, s: str) -> str: list1 = deque(list(s)) stack = [] dict1 = {} dict_key = 65 while list1: cur = list1.popleft() if cur != "]": s..
Task Scheduler - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. 내 Trash Garbage Code from typing import * from heapq import * from collections import defaultdict class Solution: def leastInterval(self, tasks: List[str], n: int) -> int: dict1 = defaultdict(int) for task in tasks..
Flatten Binary Tree to Linked List - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. Post - Order class Solution: def flatten(self, root: TreeNode) -> None: stack, temp = [], [] cur = root while True: while cur: temp.append(cur) stack.append(cur) cur = cur.left if not stack: bre..
1. Dynamic Programming class Solution: def uniquePaths(self, height: int, width: int) -> int: board = [[0] * width for _ in range(height)] for i in range(height): board[i][0] = 1 for i in range(width): board[0][i] = 1 for i in range(1, height): for j in range(1, width): board[i][j] = board[i - 1][j] + board[i][j - 1] return board[-1][-1] 예전엔 DP라고 생각도 안 났던 것 같은데 쉬운 문제지만 그래도 장족의 발전이라고 생각한다 ㅎㅎ;