LeetCode 897. Increasing Order Search Tree

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class Solution {
TreeNode *dummyHead, *curr;
public:
TreeNode* increasingBST(TreeNode* root) {
dummyHead = new TreeNode();
curr = dummyHead;
dfs(root);
return dummyHead->right;
}
void dfs(TreeNode* root) {
if (root) {
dfs(root->left);
curr->right = root;
root->left = nullptr;
curr = root;
dfs(root->right);
}
}
};