| 13 | |
| 14 | |
| 15 | int Symm(TreeNode* A,TreeNode* B) |
| 16 | { |
| 17 | if(A==NULL && B==NULL) return true; //tree is symmetric;only root node left(such a case) |
| 18 | if(A==NULL || B==NULL) return false;//after the above is checked ;see if node has only one child: then tree cannot be symmetric. |
| 19 | //use following for the rest cases. |
| 20 | return (A->val==B->val) && (Symm(A->left,B->right)) && (Symm(A->right,B->left)); |
| 21 | |
| 22 | } |
| 23 | |
| 24 | int Solution::isSymmetric(TreeNode* root) |
| 25 | { |