【LEETCODE】100-Same Tree
来源:互联网 发布:nginx配置静态页面 编辑:程序博客网 时间:2024/05/19 12:37
Same Tree
Given two binary trees, write a function to check if they are equal or not.
Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution(object): def isSameTree(self, p, q): """ :type p: TreeNode :type q: TreeNode :rtype: bool """ if p == q == None: #同为空时,True return True #elif not (p and q) or p.val != q.val: elif p==None or q==None or p.val != q.val: # 其中一个为空,或二者值不相等时,False return False else: return self.isSameTree(p.left,q.left) and self.isSameTree(p.right,q.right) #递归比较根的左右子树
0 0
- Leetcode 100 Same Tree
- LeetCode(100)Same Tree
- LeetCode 100 Same Tree
- LeetCode: Same Tree [100]
- [leetcode 100] Same Tree
- LeetCode 100 Same Tree
- LeetCode 100: Same Tree
- leetcode|100|Same Tree
- leetcode || 100、Same Tree
- LeetCode 100 Same Tree
- LeetCode 100: Same Tree
- leetcode[100]:Same Tree
- Leetcode[100]-Same Tree
- LeetCode---(100)Same Tree
- leetcode-100-Same Tree
- Leetcode # 100 Same Tree
- leetCode #100 same tree
- leetcode: (100) Same Tree
- Qt之统一的UI界面格式基调,漂亮的UI界面
- 网络解析之xml
- The app icon set named "AppIcon" did not have any applicable content.
- PySqlite 学习笔记
- Maya mental ray 焦散
- 【LEETCODE】100-Same Tree
- HDU 1698 线段树区间更新以及lazy思想
- hdu 5221 Meeting 建图+迪杰斯特拉
- 高仿IOS---Dialog(底部式)
- 面向对象的特征
- read/fread write/fwrite 的区别
- 给label加中划线
- 黑马程序员------String类
- 杭电1180 诡异的楼梯