We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 41b3975 commit 0f41ca8Copy full SHA for 0f41ca8
0100.相同的树/0100-相同的树.py
@@ -1,19 +1,18 @@
1
# Definition for a binary tree node.
2
# class TreeNode(object):
3
-# def __init__(self, x):
4
-# self.val = x
5
-# self.left = None
6
-# self.right = None
7
-
+# def __init__(self, val=0, left=None, right=None):
+# self.val = val
+# self.left = left
+# self.right = right
8
class Solution(object):
9
def isSameTree(self, p, q):
10
"""
11
:type p: TreeNode
12
:type q: TreeNode
13
:rtype: bool
14
15
- if not p:
16
- return not q
17
- if not q:
18
- return not p
+ if not p and not q:
+ return True
+ if not p or not q:
+ return False
19
return p.val == q.val and self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right)
0 commit comments