力扣 101. 对称二叉树

前置

1
2
3
4
5
class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right

解法

1
2
3
4
5
6
7
def isSymmetric(root):
def order(left, right):
if not left and not right: return True
if not left or not right: return False
return left.val == right.val and order(left.left, right.right) and order(left.right, right.left)

return order(root, root)
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2022 eightyninth
  • Visitors: | Views:

请我喝杯咖啡吧~

支付宝
微信