Bartleby Related Questions Icon

Related questions

Question

class TreeNode:

    def __init__(self, val=0, left=None, right=None):

        self.val = val

        self.left = left

        self.right = right

 

class Solution:

    def binaryTreePaths(self, root):

        def inorder_traversal(node, path, paths):

            if not node:

                return

 

            if not node.left and not node.right:

                paths.append(path + str(node.val))

                return

 

            inorder_traversal(node.left, path + str(node.val) + "->", paths)

            inorder_traversal(node.right, path + str(node.val) + "->", paths)

 

        paths = []

        inorder_traversal(root, "", paths)

        return paths

Give the space complexity of this in big O notation, give a single answer in big O

SAVE
AI-Generated Solution
AI-generated content may present inaccurate or offensive content that does not represent bartleby’s views.
bartleby
Unlock instant AI solutions
Tap the button
to generate a solution
Click the button to generate
a solution