Skip to content

Commit d8e7286

Browse files
Merge pull request #531 from Sudhir8787/patch-1
Create 114-flatten-binary-tree-to-linked-list.cpp
2 parents 6732032 + d6b5fb0 commit d8e7286

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public:
3+
void flatten(TreeNode* root) {
4+
if(!root) return;
5+
while(root)
6+
{
7+
TreeNode* temp = root->right;
8+
root->right = root->left;
9+
root->left = NULL;
10+
TreeNode* node = root;
11+
while(node->right)
12+
{
13+
node = node->right;
14+
}
15+
node->right = temp;
16+
root = root->right;
17+
}
18+
}
19+
};

0 commit comments

Comments
 (0)