Leetcode: Same Tree

Given two binary trees, write a function to check if they are equal or not.

Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
1 public boolean isSameTree(TreeNode p, TreeNode q) {
2     if(p == null && q == null) return true;
3     if(p == null || q == null) return false;
4     if(p.val == q.val)
5         return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
6     return false;
7 }
原文地址:https://www.cnblogs.com/EdwardLiu/p/3704783.html