剑指 Offer 28. 对称的二叉树

/**
 * 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) {
        return isSymmetric(root,root); 
    }
    boolean isSymmetric(TreeNode root1,TreeNode root2){
        if(root1 == null && root2 == null){
             return true;
         }   
        if(root1 == null || root2 == null){
            return false;
        }
        if(root1.val != root2.val){
            return false;
        }
        return isSymmetric(root1.left,root2.right)&& isSymmetric(root1.right,root2.left);
    }
}

 

posted @ 2020-12-14 18:32  peanut_zh  阅读(36)  评论(0编辑  收藏  举报