Very clean python code

  • 0
    class Solution(object):
        def binaryTreePaths(self, root):
            if not root:
                return []
            if not root.left and not root.right:
                return [str(root.val)]
            return ['{}->{}'.format(root.val, p)
                    for subtree in (root.left, root.right) if subtree
                    for p in self.binaryTreePaths(subtree)]

Log in to reply

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