Created
December 18, 2020 10:20
-
-
Save vamsitallapudi/3654dcef136bdfb541b8f951c7574f5c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
def preorderTraversal(self, root: TreeNode) -> List[int]: | |
# to return an empty array if root is empty | |
if not root: | |
return [] | |
# appending the root value in array and recursively going into left and right subtrees | |
return [root.val] + self.preorderTraversal(root.left) + self.preorderTraversal(root.right) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment