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 15a9a1d commit 32deff5Copy full SHA for 32deff5
same-tree/samthekorean.py
@@ -0,0 +1,17 @@
1
+# Time complexity : O(n)
2
+# Space complexity : O(n)
3
+class Solution:
4
+ def isSameTree(self, p: Optional[TreeNode], q: Optional[TreeNode]) -> bool:
5
+ if not p and not q:
6
+ return True
7
+
8
+ if not p and q:
9
+ return False
10
11
+ if p and not q:
12
13
14
+ if p.val != q.val:
15
16
17
+ return self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right)
0 commit comments