题目:
题解:
class Solution:def binaryTreePaths(self, root: TreeNode) -> List[str]:paths = list()if not root:return pathsnode_queue = collections.deque([root])path_queue = collections.deque([str(root.val)])while node_queue:node = node_queue.popleft()path = path_queue.popleft()if not node.left and not node.right:paths.append(path)else:if node.left:node_queue.append(node.left)path_queue.append(path + '->' + str(node.left.val))if node.right:node_queue.append(node.right)path_queue.append(path + '->' + str(node.right.val))return paths