leetcode-----101. 对称二叉树

/**
 * 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 isSameTree(root, root);
    }

    public boolean isSameTree(TreeNode p, TreeNode q) {
        if (p == null || q== null) return p == q;
        return (p.val == q.val) && isSameTree(p.left, q.right) && isSameTree(p.right, q.left);
    }
}
posted @ 2020-04-05 21:05  景云ⁿ  阅读(80)  评论(0编辑  收藏  举报