https://leetcode-cn.com/problems/symmetric-tree/
把第一题做完其实第二题也差不多了,我们把这个二叉树看成两个,然后把第一题的代码中的right改成left应该就可行.
然而事情总没你想象中的那么简单…

写完代码10分钟,修个bug1小时
# 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:
if not root:
return True
if not root.right and not root.left:
return True
def s1(p:TreeNode,q:TreeNode):
if not p and not q:
return True
if not p or not q:
return False
if p.val !=q.val:
return False
return s1(p.right,q.left) and s1(p.left,q.right)
return s1(root.left,root.right)
真的就是把上篇文章的代码复制粘贴然后多了两个判断。。。
GG

1211

被折叠的 条评论
为什么被折叠?



