func increasingBST(_ root: TreeNode?) -> TreeNode? {
var array = Array<Int>()
dealTree(root, &array)
var node : TreeNode?
var tempNode : TreeNode?
for i in 0..<array.count {
if node == nil {
node = TreeNode(array[i])
tempNode = node
}else {
let node1 = TreeNode(array[i])
node?.right = node1
node = node1
}
}
return tempNode
}
func dealTree(_ root:TreeNode? ,_ array:inout Array<Int>) {
if root == nil {
return
}
dealTree(root?.left,&array)
array.append((root?.val)!)
dealTree(root?.right,&array)
}
网友评论