Skip to content

Commit bcf3f63

Browse files
committed
added more explainations on the space complexity.
1 parent d1f3963 commit bcf3f63

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

subtree-of-another-tree/samthekorean.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Time complexity : O(n*m)
2-
# Space complexity : Space complexity: O(h) h is the height of the call stack during the recursive traversal.
1+
# Time complexity: O(n*m)
2+
# Space complexity: O(r + s) isSubtree() method is internally calling isSameTree() so the total depth of the stack is sum of isSubtree() call stacks and isSameTree()'s call stacks.
33
class Solution:
44
def isSubtree(self, p: Optional[TreeNode], q: Optional[TreeNode]) -> bool:
55
if not q:

0 commit comments

Comments
 (0)