标签:def false val 技术 img nod tree type http
思路:递归。
终止条件是两个节点都为空,return True;
或者两个节点中有一个为空,return False;
或者两个节点的值不相等,return False;
class Solution(object):
def isSymmetric(self, root):
"""
:type root: TreeNode
:rtype: bool
"""
if not root:
return True
return self.digui(root.left, root.right)
def digui(self, left, right):
if left.val != right.val:
return False
if not left or not right:
return False
if not left and not right:
return True
return self.digui(left.left, right.right) and self.digui(left.right, right.left)
标签:def false val 技术 img nod tree type http
原文地址:https://www.cnblogs.com/panweiwei/p/13065391.html