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 596556f commit 9c14f52Copy full SHA for 9c14f52
subtree-of-another-tree/TonyKim9401.java
@@ -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
+// TC: O(n * m)
+// need to check all nodes and subRoot nodes in the worst case
+// SC: O(h1 + h2)
+// the high of root = h1 + the high of subRoot h2 => O(h1 + h2)
5
class Solution {
6
public boolean isSubtree(TreeNode root, TreeNode subRoot) {
7
if (root == null) return false;
0 commit comments