https://leetcode.com/problems/binary-tree-inorder-traversal/
Given the root of a binary tree, return the inorder traversal of its nodes' values.
root
Input: root = [1,null,2,3] Output: [1,3,2]
# 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: TreeNode) -> List[int]: to_ret = [] def inorder(root): if not root: return inorder(root.left) to_ret.append(root.val) inorder(root.right) inorder(root) return to_ret
Last updated 3 years ago
Example 1: