mirror of
https://github.com/devenperez/leetcode.git
synced 2026-06-15 01:07:07 +00:00
Time: 0 ms (100%), Space: 18 MB (11.85%) - LeetHub
This commit is contained in:
@@ -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
|
||||||
Reference in New Issue
Block a user