Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution
- {
- public:
- void inorder_dfs(Node * node, Node * & parent) {
- if(node == NULL) {
- return;
- }
- inorder_dfs(node->left, parent);
- parent->left = NULL;
- parent->right = node;
- parent = node;
- inorder_dfs(node->right, parent);
- }
- Node *flattenBST(Node *root)
- {
- Node * tmp = new Node(-1);
- Node * parent = tmp;
- inorder_dfs(root, parent);
- parent->left = NULL;
- parent->right = NULL;
- Node * res = tmp->right;
- return res;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement