MCPcopy Create free account
hub / github.com/codedecks-in/LeetCode-Solutions / isSameTree

Method isSameTree

Java/Same-Tree.java:19–40  ·  view source on GitHub ↗
(TreeNode p, TreeNode q)

Source from the content-addressed store, hash-verified

17
18class Solution {
19 public boolean isSameTree(TreeNode p, TreeNode q) {
20 if (p == null && q == null) {
21 return true;
22 }
23 else if (p == null) {
24 return false;
25 }
26 else if (q == null) {
27 return false;
28 }
29 else {
30 if (p.val != q.val) {
31 return false;
32 }
33 else {
34 boolean left = isSameTree(p.left, q.left);
35 boolean right = isSameTree(p.right, q.right);
36
37 return left && right;
38 }
39 }
40 }
41}
42

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected