题目:
题解:
func flatten(root *TreeNode) {
curr := root
for curr != nil {
if curr.Left != nil {
next := curr.Left
predecessor := next
for predecessor.Right != nil {
predecessor = predecessor.Right
}
predecessor.Right = curr.Right
curr.Left, curr.Right = nil, next
}
curr = curr.Right
}
}