Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     TreeNode* invertTree(TreeNode* root) {
  4.        
  5.         if(root == NULL) return 0;
  6.        
  7.         if(root->left == NULL && root->right == NULL)
  8.             return root;
  9.        
  10.         root->left = invertTree(root->left);
  11.         root->right = invertTree(root->right);
  12.        
  13.         swap(root->left, root->right);
  14.        
  15.         return root;
  16.     }
  17. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement