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 799fcc8 commit 681cef5Copy full SHA for 681cef5
SameTree.py
@@ -0,0 +1,29 @@
1
+# coding: utf-8
2
+__author__ = 'devin'
3
+
4
+# Definition for a binary tree node.
5
+# class TreeNode(object):
6
+# def __init__(self, x):
7
+# self.val = x
8
+# self.left = None
9
+# self.right = None
10
11
+class Solution(object):
12
+ def isSameTree(self, p, q):
13
+ """
14
+ :type p: TreeNode
15
+ :type q: TreeNode
16
+ :rtype: bool
17
18
+ if p is None and q is None:
19
+ return True
20
21
+ if p is not None and q is not None and p.val == q.val:
22
+ left_tree = self.isSameTree(p.left, q.left)
23
+ right_tree = self.isSameTree(p.right, q.right)
24
+ if left_tree and right_tree:
25
26
+ else:
27
+ return False
28
29
0 commit comments