Time Complexity:
Space Complexity:
# 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]:
def traversal(node: TreeNode, trav: List[int]) -> None:
# node not exist
if not node:
return
# inorder: left child -> parent -> right child
if node.left:
traversal(node.left, trav)
trav.append(node.val)
if node.right:
traversal(node.right, trav)
res = list()
traversal(root, res)
return res
It is a best solution found that very popular and helpful
https://www.youtube.com/watch?v=WHUMCUuktJk&ab_channel=EricProgramming