전체 글(221)
-
[LeetCode] Decode String (Python)
보호되어 있는 글입니다.
2024.03.08 -
[LeetCode] Implement Stack using Queues (Python)
from collections import deque class MyStack: def __init__(self): self.stack1 = deque() self.stack2 = deque() def push(self, x: int) -> None: self.stack1.append(x) def pop(self) -> int: while len(self.stack1) > 1: temp = self.stack1.popleft() self.stack2.append(temp) if len(self.stack1) == 1: answer = self.stack1.popleft() self.stack1, self.stack2 = self.stack2, self.stack1 return answer def top(..
2024.03.08 -
[LeetCode] Implement Queue using Stacks (Python)
class MyQueue: def __init__(self): self.stack_input = [] self.stack_output = [] def push(self, x: int) -> None: self.stack_input.append(x) def pop(self) -> int: length = len(self.stack_input) - 1 for _ in range(length): self.stack_output.append(self.stack_input.pop()) front = self.stack_input.pop() for _ in range(length): self.stack_input.append(self.stack_output.pop()) return front def peek(sel..
2024.03.08 -
[LeetCode] Binary Tree Inorder Traversal (Python)
# Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = left # self.right = right class Solution: def inorderTraversal(self, root: Optional[TreeNode]) -> List[int]: answer = [] def dfs(node): if node is not None: dfs(node.left) answer.append(node.val) dfs(node.right) dfs(root) return answer
2024.03.07 -
[LeetCode] Clone Graph (Python)
보호되어 있는 글입니다.
2024.03.07 -
[LeetCode] Target Sum (Python)
보호되어 있는 글입니다.
2024.03.07