Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9c14f52

Browse files
committedNov 22, 2024·
Subtree Of Another Tree TC, SC re-calculation
1 parent 596556f commit 9c14f52

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed
 

‎subtree-of-another-tree/TonyKim9401.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// TC: O(n)
2-
// need to check all nodes in the worst case
3-
// SC: O(n)
4-
// recursion requires O(n) SC in the worst case
1+
// TC: O(n * m)
2+
// need to check all nodes and subRoot nodes in the worst case
3+
// SC: O(h1 + h2)
4+
// the high of root = h1 + the high of subRoot h2 => O(h1 + h2)
55
class Solution {
66
public boolean isSubtree(TreeNode root, TreeNode subRoot) {
77
if (root == null) return false;

0 commit comments

Comments
 (0)
Please sign in to comment.