Solve 94. Binary Tree Inorder Traversal

This commit is contained in:
ktkovachev 2024-04-08 17:07:41 +01:00 committed by GitHub
parent b173b159ea
commit 85af04c566
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -0,0 +1,14 @@
# 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]:
def inorderInner(root: Optional[TreeNode], out: List[int]):
if root is None: return out
inorderInner(root.left, out)
out.append(root.val)
return inorderInner(root.right, out)
return inorderInner(root, [])