这里有leetcode题集分类整理!!!![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/495d63aab54fda879d7a3eccff124aaa.png)
AC代码:
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode() {}
* TreeNode(int val) { this.val = val; }
* TreeNode(int val, TreeNode left, TreeNode right) {
* this.val = val;
* this.left = left;
* this.right = right;
* }
* }
*/
class Solution {
public TreeNode increasingBST(TreeNode root) {
List<Integer> res = new ArrayList<Integer>() ;
inorder(root, res);
TreeNode dummyNode = new TreeNode(-1);
TreeNode currNode = dummyNode;
for(int val: res) {
currNode.right = new TreeNode(val);
currNode = currNode.right;
}
return dummyNode.right;
}
public void inorder(TreeNode node, List res ) {
if(node == null) {
return ;
}
inorder(node.left, res);
res.add(node.val);
inorder(node.right, res);
}
}