Created
June 20, 2018 09:08
-
-
Save Kishy-nivas/4e7b52f2715992c5e14b983bbf4eed7e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for a binary tree node. | |
* struct TreeNode { | |
* int val; | |
* TreeNode *left; | |
* TreeNode *right; | |
* TreeNode(int x) : val(x), left(NULL), right(NULL) {} | |
* }; | |
*/ | |
class Solution { | |
public: | |
TreeNode* invertTree(TreeNode* root) { | |
if(root == nullptr) | |
return nullptr; | |
TreeNode* left = invertTree(root->left); | |
TreeNode* right = invertTree(root->right); | |
root->left = right; | |
root->right = left; | |
return root; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment