Skip to content

Instantly share code, notes, and snippets.

@Kishy-nivas
Created June 20, 2018 09:08
Show Gist options
  • Save Kishy-nivas/4e7b52f2715992c5e14b983bbf4eed7e to your computer and use it in GitHub Desktop.
Save Kishy-nivas/4e7b52f2715992c5e14b983bbf4eed7e to your computer and use it in GitHub Desktop.
/**
* 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