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 d2bfffb commit d1907a1Copy full SHA for d1907a1
subtree-of-another-tree/printjin-gmailcom.py
@@ -0,0 +1,13 @@
1
+class Solution:
2
+ def isSubtree(self, root, subRoot):
3
+ if not root:
4
+ return False
5
+ if self.isSameTree(root, subRoot):
6
+ return True
7
+ return self.isSubtree(root.left, subRoot) or self.isSubtree(root.right, subRoot)
8
+ def isSameTree(self, s, t):
9
+ if not s and not t:
10
11
+ if not s or not t or s.val != t.val:
12
13
+ return self.isSameTree(s.left, t.left) and self.isSameTree(s.right, t.right)
0 commit comments