101. Symmetric Tree

class Solution {
    public boolean isSymmetric(TreeNode root) {
        return recursion(root, root);
    }
    
    private boolean recursion(TreeNode first, TreeNode second){
        if(first==null || second == null){
            return first==second;
        }
        
        if(first.val!=second.val) return false;
        if(recursion(first.left, second.right)){
            return recursion(first.right, second.left);
        }else{
            return false;
        }
    }
}

Last updated