irborrero
9/4/2019 - 9:03 PM

isSymmetric

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
class Solution {
    public boolean isSymmetric(TreeNode root) {
        if(root == null) return true; //root null 
        return isMirror(root.left, root.right);    
    }
    
    public boolean isMirror(TreeNode mirrorLeft, TreeNode mirrorRight){    
        //TODO: Base Cases
       if(mirrorLeft == null || mirrorRight == null) {
           if(mirrorLeft == null && mirrorRight == null) return true;
           else return false;
       }
        
        //TODO: Body of Recursion
 
           if(isMirror(mirrorLeft.left, mirrorRight.right) 
              && isMirror(mirrorLeft.right, mirrorRight.left) 
                && mirrorLeft.val == mirrorRight.val) 
                    return true;
           else return false;
    }
}