From cfa865059fd43e31fb9cc562e098edd5664db025 Mon Sep 17 00:00:00 2001 From: Deven <63876261+devenperez@users.noreply.github.com> Date: Wed, 26 Nov 2025 20:40:36 -0500 Subject: [PATCH] Time: 0 ms (100%), Space: 18 MB (11.85%) - LeetHub --- .../0094-binary-tree-inorder-traversal.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 0094-binary-tree-inorder-traversal/0094-binary-tree-inorder-traversal.py diff --git a/0094-binary-tree-inorder-traversal/0094-binary-tree-inorder-traversal.py b/0094-binary-tree-inorder-traversal/0094-binary-tree-inorder-traversal.py new file mode 100644 index 0000000..0c1e8e4 --- /dev/null +++ b/0094-binary-tree-inorder-traversal/0094-binary-tree-inorder-traversal.py @@ -0,0 +1,29 @@ +# 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]: + """ + Complexities: + Time: O(n) + Space: O(n) + + where n = total node in graph + """ + + if not root: + return [] + + arr = [] + if root.left: + arr += self.inorderTraversal(root.left) + + arr += [root.val] + + if root.right: + arr += self.inorderTraversal(root.right) + + return arr \ No newline at end of file