knakul853

Untitled

Jun 10th, 2020
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. /**
  2. *knakul853
  3.  **/
  4. class Solution {
  5. public:
  6.     bool isSymmetric(TreeNode* root) {
  7.        
  8.         if( !root ) return true;
  9.        
  10.        return  solve(root->left, root->right);
  11.        
  12.     }
  13.    
  14.     bool solve(TreeNode* t1, TreeNode* t2)
  15.     {
  16.         if( t1 == t2 ) return true;
  17.         if( !t1 || !t2) return false;
  18.        
  19.         if(t1->val != t2->val) return false;
  20.        
  21.         return solve(t1->left, t2->right) && solve(t1->right, t2->left);
  22.     }
  23. };
Add Comment
Please, Sign In to add comment