leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0226.cpp (433B)
0 class Solution {
1 public:
2 TreeNode *invertTree(TreeNode *root) {
3 if (!root) return nullptr;
5 stack<TreeNode *> st;
6 st.push(root);
7 while (!st.empty()) {
8 TreeNode *root = st.top();
9 st.pop();
10 swap(root->left, root->right);
11 if (root->left) st.push(root->left);
12 if (root->right) st.push(root->right);
13 }
14 return root;
15 }
16 };