From 85af04c56687b5e118ab8d2852f22c910600e448 Mon Sep 17 00:00:00 2001 From: ktkovachev <143198904+ktkovachev@users.noreply.github.com> Date: Mon, 8 Apr 2024 17:07:41 +0100 Subject: [PATCH] Solve 94. Binary Tree Inorder Traversal --- python/94_binary_tree_inorder_traversal.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 python/94_binary_tree_inorder_traversal.py diff --git a/python/94_binary_tree_inorder_traversal.py b/python/94_binary_tree_inorder_traversal.py new file mode 100644 index 0000000..f6b7b69 --- /dev/null +++ b/python/94_binary_tree_inorder_traversal.py @@ -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, [])