leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0897.cpp (535B)


0 class Solution { 1 public: 2 TreeNode *increasingBST(TreeNode *root) { 3 TreeNode *head, *tmp; 4 tmp = head = new TreeNode(); 5 stack<TreeNode *> st; 6 while (true) { 7 while (root) { 8 st.push(root); 9 root = root->left; 10 } 11 if (st.empty()) break; 12 root = st.top(); 13 st.pop(); 14 tmp = tmp->right = root; 15 tmp->left = nullptr; 16 root = root->right; 17 } 18 return head->right; 19 } 20 };