Python iterable


  • 0
    F
    class Solution(object):
    def preorderTraversal(self, root):
        """
        :type root: TreeNode
        :rtype: List[int]
        """
        if not root: return []
        stack, res=[root], []
        while stack:
            node=stack.pop()
            res+=[node.val]
            if node.right: stack+=[node.right]
            if node.left: stack+=[node.left]
        return res

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.