Problem Solving/LeetCode
2023.12.09 Today's Challenge
fabichoi
2023. 12. 9. 23:45
https://leetcode.com/problems/binary-tree-inorder-traversal/
Binary Tree Inorder Traversal - LeetCode
Can you solve this real interview question? Binary Tree Inorder Traversal - Given the root of a binary tree, return the inorder traversal of its nodes' values. Example 1: [https://assets.leetcode.com/uploads/2020/09/15/inorder_1.jpg] Input: root = [1,nu
leetcode.com
트리 순회 문제!
class Solution:
def inorderTraversal(self, root: Optional[TreeNode]) -> List[int]:
if not root:
return []
return self.inorderTraversal(root.left) + [root.val] + self.inorderTraversal(root.right)
반응형