[LeetCode] Binary Tree Inorder Traversal (Python)
2024. 3. 7. 10:28ㆍ알고리즘
# 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
'알고리즘' 카테고리의 다른 글
[LeetCode] Implement Stack using Queues (Python) (0) | 2024.03.08 |
---|---|
[LeetCode] Implement Queue using Stacks (Python) (0) | 2024.03.08 |
[LeetCode] Clone Graph (Python) (0) | 2024.03.07 |
[LeetCode] Target Sum (Python) (0) | 2024.03.07 |
[LeetCode] Daily Temperatures (Python) (0) | 2024.03.06 |