Skip to content

Instantly share code, notes, and snippets.

@oliverwreath
Created February 24, 2019 22:28
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
public TreeNode increasingBST(TreeNode root) {
// corner cases
if (root == null) {
return null;
}
return inorder(root, null);
}
private TreeNode inorder(TreeNode root, TreeNode tail) {
// corner cases
if (root == null) {
return tail;
}
TreeNode head = inorder(root.left, root);
root.left = null;
root.right = inorder(root.right, tail);
return head;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment