leetcode刷题笔记19

面试题28. 对称的二叉树

请实现一个函数,用来判断一棵二叉树是不是对称的。如果一棵二叉树和它的镜像一样,那么它是对称的。

# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None
class Solution:    
	def isSymmetric(self, root: TreeNode) -> bool:
		def recur(L,R):
			if not L and not R: return True
			if not L or not R or L.val != R.val: return False
			return recur(L.left,R.right) and recur(L.right,R.left)
		return recur(root.left,root.right) if root else True
		

你可能感兴趣的:(leetcode刷题笔记19)