- Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsameTree.java
More file actions
Latest commit
25 lines (24 loc) · 557 Bytes
/
Copy pathsameTree.java
File metadata and controls
25 lines (24 loc) · 557 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/**
* Definition for binary tree
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
publicclassSolution {
publicbooleanisSameTree(TreeNodep, TreeNodeq) {
if(p==null&&q==null) {
returntrue;
}
if (p==null||q==null) {
returnfalse;
}
if(p.val==q.val) {
returnisSameTree(p.left,q.left)&&isSameTree(p.right,q.right);
} else {
returnfalse;
}
}
}