public class Solution {
public boolean isSameTree(TreeNode p, TreeNode q) {
if (p == null && q == null) return true;
// not all p and q are null which means one of them is null the other is not null.
// cannot be the same tree, return false.
if (p == null || q == null) return false;
if (p.val == q.val)
return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
return false;
}
}
Leetcode 100. Same Tree
最新推荐文章于 2022-03-19 13:19:57 发布