Skip to content

Commit 55cab6b

Browse files
edit 572
1 parent 8c4892a commit 55cab6b

File tree

1 file changed

+3
-6
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+3
-6
lines changed

src/main/java/com/fishercoder/solutions/_572.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,17 @@
3838
Return false.
3939
*/
4040
public class _572 {
41+
4142
public boolean isSubtree(TreeNode s, TreeNode t) {
4243
if (s == null && t == null) return true;
43-
return dfs(s, t);
44-
}
45-
46-
private boolean dfs(TreeNode s, TreeNode t) {
4744
boolean isSubTree = false;
4845
if (s != null && t != null && s.val == t.val) isSubTree = isSameTree(s, t);
4946
if (isSubTree) return true;
5047
boolean isSubTreeLeft = false;
51-
if (s.left != null) isSubTreeLeft= dfs(s.left, t);
48+
if (s.left != null) isSubTreeLeft= isSubtree(s.left, t);
5249
if (isSubTreeLeft) return true;
5350
boolean isSubTreeRight = false;
54-
if (s.right != null) isSubTreeRight = dfs(s.right, t);
51+
if (s.right != null) isSubTreeRight = isSubtree(s.right, t);
5552
if (isSubTreeRight) return true;
5653
return false;
5754
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy