Skip to content

Commit

Permalink
226
Browse files Browse the repository at this point in the history
  • Loading branch information
isinsuarici committed Dec 11, 2022
1 parent 9bc66a6 commit cfea55b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions E_226_InvertBinaryTree.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
* };
*/
class Solution {
public:
TreeNode* invertTree(TreeNode* root) {
if(root == 0) return 0;
TreeNode* temp = root->left;
root->left = invertTree(root->right);
root->right = invertTree(temp);
return root;
}
};

0 comments on commit cfea55b

Please sign in to comment.