Skip to content

Commit de49dca

Browse files
committed
feat:add Solution.cpp for 0114. Flatten Binary Tree to Linked List
1 parent 52de171 commit de49dca

File tree

1 file changed

+16
-0
lines changed
  • solution/0100-0199/0114.Flatten Binary Tree to Linked List

1 file changed

+16
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public:
3+
void flatten(TreeNode* root) {
4+
TreeNode* cur = root;
5+
while (cur) {
6+
if (cur->left) {
7+
TreeNode* p = cur->left;
8+
while (p->right) p = p->right;
9+
p->right = cur->right;
10+
cur->right = cur->left;
11+
cur->left = nullptr;
12+
}
13+
cur = cur->right;
14+
}
15+
}
16+
};

0 commit comments

Comments
 (0)