leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0114.cpp (542B)
0 class Solution {
1 public:
2 void flatten(TreeNode *root) {
3 TreeNode *crnt = new TreeNode(-1);
4 stack<TreeNode *> st;
5 st.push(root);
6 while (!st.empty()) {
7 TreeNode *root = st.top();
8 st.pop();
9 crnt->right = root;
10 while (root) {
11 crnt = root;
12 if (root->right) st.push(root->right);
14 root->right = root->left;
15 root->left = nullptr;
16 root = root->right;
17 }
18 }
19 }
20 };