897. Increasing Order Search Tree
/**
* 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 {
TreeNode current=null;
TreeNode head=null;
public TreeNode increasingBST(TreeNode root) {
if(root==null){
return null;
}
increasingBST(root.left);
if(current==null){
current=root;
head=current;
}else{
current.right=root;
current.left=null;
current=current.right;
}
increasingBST(root.right);
return head;
}
}