Skip to content

Latest commit

 

History

History
27 lines (21 loc) · 855 Bytes

28. 对称的二叉树.md

File metadata and controls

27 lines (21 loc) · 855 Bytes

28. 对称的二叉树

NowCoder

题目描述


解题思路

boolean isSymmetrical(TreeNode pRoot) {
    if (pRoot == null)
        return true;
    return isSymmetrical(pRoot.left, pRoot.right);
}

boolean isSymmetrical(TreeNode t1, TreeNode t2) {
    if (t1 == null && t2 == null)
        return true;
    if (t1 == null || t2 == null)
        return false;
    if (t1.val != t2.val)
        return false;
    return isSymmetrical(t1.left, t2.right) && isSymmetrical(t1.right, t2.left);
}