전체 글(224)
-
[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 -
[LeetCode] Evaluate Reverse Polish Notation (Python)
import math class Solution: def evalRPN(self, tokens: List[str]) -> int: operation = ["+", "-", "*", "/"] stack = [] if len(tokens) == 1: return int(tokens[0]) for i in range(len(tokens)): if tokens[i] not in operation: stack.append(int(tokens[i])) else: num1 = stack.pop() num2 = stack.pop() new_num = 0 if tokens[i] == "+": new_num = num2 + num1 elif tokens[i] == "-": new_num = num2 - num1 elif ..
2024.03.06 -
[LeetCode] Daily Temperatures (Python)
보호되어 있는 글입니다.
2024.03.06 -
[LeetCode] Valid Parentheses (Python)
class Solution: def isValid(self, s: str) -> bool: stack=[] brackets={'}':'{',')':'(',']':'['} for bracket in s: if bracket in brackets.values(): stack.append(bracket) else: if stack and brackets[bracket]==stack[-1] : stack.pop() else: return False if stack: return False return True
2024.03.06