一、题目内容
二、题解
解法1:
思路
二叉搜索树的中序遍历就是从小到大,所以可以通过中序遍历解题,递归
代码
class Solution {private Node pre, head;public Node treeToDoublyList(Node root) {if (root == null) {return null;}recur(root);head.left = pre;pre.right = head;return head;}private void recur(Node root) {if (root == null) {return;}recur(root.left);if (pre != null) { //非第一个节点pre.right = root;} else { //root为双向链表第一个节点head = root;}root.left = pre;pre = root;recur(root.right);}}

