这篇文章是程序自动发表的,详情可以见
这里
href="http://ounix1xcw.bkt.clouddn.com/github.markdown.css" rel="stylesheet">
href="http://ounix1xcw.bkt.clouddn.com/github.markdown.css" rel="stylesheet">
这是leetcode的第101题--Symmetric Tree
题目
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). 思路 挺简单的,不过对称挺美的
show me the code
# Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution(object): def isSymmetric(self, root): """ :type root: TreeNode :rtype: bool """ if not root:return True return self.judge(root.left,root.right) def judge(self,p,q): if not p and not q:return True if (not p and q) or (p and not q):return False return p.val == q.val and self.judge(p.left,q.right) and self.judge(p.right,q.left)

本文介绍LeetCode上第101题“对称二叉树”的解题思路与代码实现。该题要求判断一棵二叉树是否关于其中心对称。通过对二叉树节点进行递归比较,实现简洁高效的解决方案。

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



