###########################################################################
#                                                                         #
# Author: Daniel Mock                                                     #
#                                                                         #
# Purpose: To document progress in learning algorithms & data structures  #
#                                                                         #
# References: This question was generated by leetcode.com. The solution   #
# to the question was generated by Daniel Mock.                           #
#                                                                         #
###########################################################################
# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution:
    def preorderTraversal(self, root: TreeNode) -> List[int]:


        #Iterative
        if root is None: return root
        stack = [root]
        lst = []
        while len(stack) > 0:
            node = stack.pop()
            if node is not None:
                lst.append(node.val)
                stack.append(node.right)
                stack.append(node.left)
            else:continue
        return lst

##############################################
        '''
        #Recursive
        if root is None: return None
        stack = [root]
        res = []

        while stack:
            node = stack.pop()
            res.append(node.val)
            if node.right: stack.append(node.right)
            if node.left: stack.append(node.left)
        return res
        '''    
