Skip to content

Commit ca10e36

Browse files
Both trees are same or not
1 parent 10f9bf6 commit ca10e36

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

BinaryTrees/Same_tree.java

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution {
2+
public boolean isSameTree(TreeNode p, TreeNode q) {
3+
if(p==null && q==null)
4+
return true;
5+
else if((p==null && q!=null) || (q==null && p!=null) || (p.val!=q.val))
6+
return false;
7+
else
8+
return (isSameTree(p.left,q.left) && isSameTree(p.right,q.right));
9+
}
10+
}

0 commit comments

Comments
 (0)