Created
July 25, 2015 07:21
-
-
Save jporcelli/32bdef3ddbb1e4750740 to your computer and use it in GitHub Desktop.
https://leetcode.com/problems/invert-binary-tree/ Invert Binary Tree - Trivia: This problem was inspired by this original tweet by Max Howell: Google: 90% of our engineers use the software you wrote (Homebrew), but you can’t invert a binary tree on a whiteboard so fuck off.
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) return NULL; | |
TreeNode *temp = invertTree(root->right); | |
root->right = invertTree(root->left); | |
root->left = temp; | |
return root; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment