/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public boolean isSameTree(TreeNode p, TreeNode q) {
if (p == null && q == null) return true;
if (p == null && q != null) return false;
if (p != null && q == null) return false;
if (p.val != q.val) return false;
if (!isSameTree(p.left, q.left)) return false;
if (!isSameTree(p.right, q.right)) return false;
return true;
}
}
LeetCode 100. Same Tree
最新推荐文章于 2022-03-19 13:19:57 发布