Recursive Ruby Solution


  • 1
    def preorder_traversal(root)
        ans = []
        return ans if root == nil
        ans << root.val << preorder_traversal(root.left) << preorder_traversal(root.right)
        ans.flatten
    end

Log in to reply
 

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