地址:https://leetcode-cn.com/problems/increasing-order-search-tree/
/** * Definition for a binary tree node. * class TreeNode { * public $val = null; * public $left = null; * public $right = null; * function __construct($value) { $this->val = $value; } * } */ class Solution { /** * @param TreeNode $root * @return TreeNode */ function increasingBST($root) { $res = []; $this->helper($root,$res); $root = new TreeNode(0); $node = $root; while(!empty($res)){ $val=array_shift($res); $node->right = new TreeNode($val); $node = $node->right; } return $root->right; } public function helper($root,&$res){ if($root == null) return ; $this->helper($root->left,$res); $res[]=$root->val; $this->helper($root->right,$res); } }