题目:
题解:
type pair struct {node *TreeNodenum int
}func sumNumbers(root *TreeNode) (sum int) {if root == nil {return}queue := []pair{{root, root.Val}}for len(queue) > 0 {p := queue[0]queue = queue[1:]left, right, num := p.node.Left, p.node.Right, p.numif left == nil && right == nil {sum += num} else {if left != nil {queue = append(queue, pair{left, num*10 + left.Val})}if right != nil {queue = append(queue, pair{right, num*10 + right.Val})}}}return
}