101. Symmetric Tree

判断二叉树是否对称

def isSymmetric(self, root):
    def isSym(L,R):
        if not L and not R: return True
        if L and R and L.val == R.val: 
            return isSym(L.left, R.right) and isSym(L.right, R.left)
        return False
    return isSym(root, root)

同时遍历左子树和右子树,判断是否对称

你可能感兴趣的:(101. Symmetric Tree)