MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / isSameTree

Method isSameTree

LeetCode_problems/Same Tree/sameTree.java:27–35  ·  view source on GitHub ↗
(TreeNode p, TreeNode q)

Source from the content-addressed store, hash-verified

25
26class Solution {
27 public boolean isSameTree(TreeNode p, TreeNode q) {
28 // p and q are both null
29 if (p == null && q == null) return true;
30 // one of p and q is null
31 if (q == null || p == null) return false;
32 if (p.val != q.val) return false;
33 return isSameTree(p.right, q.right) &&
34 isSameTree(p.left, q.left);
35 }
36}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected