Skip to content

Commit 3f2e7d6

Browse files
authored
Update Invert-Binary-Tree.cpp
1 parent bde04a6 commit 3f2e7d6

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

June-LeetCoding-Challenge/01-Invert-Binary-Tree/Invert-Binary-Tree.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,17 @@ class Solution {
1212
dfs(root, &root2);
1313
return root2;
1414
}
15-
};
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

Comments
 (0)