1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| class Solution { TreeNode r = new TreeNode(); public TreeNode increasingBST(TreeNode root) { TreeNode res = r; dfs(root); return res.right; }
public void dfs(TreeNode root){ if(root == null){ return; } dfs(root.left); TreeNode tmp = new TreeNode(root.val); r.right = tmp; r = tmp;
dfs(root.right); } }
|