We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent bde04a6 commit 3f2e7d6Copy full SHA for 3f2e7d6
June-LeetCoding-Challenge/01-Invert-Binary-Tree/Invert-Binary-Tree.cpp
@@ -12,4 +12,17 @@ class Solution {
12
dfs(root, &root2);
13
return root2;
14
}
15
-};
+};
16
+
17
+class Solution {
18
+public:
19
+ TreeNode* invertTree(TreeNode* root) {
20
+ if(!root) return nullptr;
21
+ auto left = (root->left)?invertTree(root->left):nullptr;
22
+ auto right = (root->right)?invertTree(root->right):nullptr;
23
+ root->left = right;
24
+ root->right = left;
25
+ return root;
26
+ }
27
28
0 commit comments