题目:
题解:
func connect(root *Node) *Node {
start := root
for start != nil {
var nextStart, last *Node
handle := func(cur *Node) {
if cur == nil {
return
}
if nextStart == nil {
nextStart = cur
}
if last != nil {
last.Next = cur
}
last = cur
}
for p := start; p != nil; p = p.Next {
handle(p.Left)
handle(p.Right)
}
start = nextStart
}
return root
}