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라고 생각도 안 났던 것 같은데 쉬운 문제지만 그래도 장족의 발전이라고 생각한다 ㅎㅎ;
Minimum Path Sum - 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을 이용한 DFS(TLE) from typing import * class Solution: def minPathSum(self, grid: List[List[int]]) -> int: answer = float("inf") s_x, s_y = 0, 0 t_x, t_y = len(grid) - 1, len(grid[0]) - 1 height, width = t_x + ..
Binary Tree Right Side View - 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. Queue를 이용한 풀이 class Solution: def rightSideView(self, root: TreeNode) -> List[int]: if not root: return [] answer, trace = [], defaultdict(int) q = deque([(root, 0)]) while q: cur_node, cur_level = q.p..