LeetCode刷题笔记(101,对称二叉树,Easy)

/**
 * 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 isMirror(root,root);
        
    }
    public boolean isMirror(TreeNode p,TreeNode q){
        if(p == null && q == null){
            return true;
        }
        if(p == null || q == null){
            return false;
        }
        return (p.val == q.val) && isMirror(p.left,q.right) && isMirror(p.right,q.left);

    }
}

 

你可能感兴趣的:(LeetCode刷题笔记(101,对称二叉树,Easy))