提交 66dfe675 编写于 作者: GreyZeng's avatar GreyZeng

leetcode 100 same tree

上级 f829dc38
......@@ -3,11 +3,13 @@ package git.snippet.tree;
// 判断两颗树是否结构相同
// Two binary trees are considered the same if they are structurally identical, and the nodes have
// the same value.
// https://leetcode.com/problems/same-tree
public class LeetCode_0100_SameTree {
public boolean isSameTree(TreeNode p, TreeNode q) {
if (p == null || q == null) {
return p == null && q == null;
// 两个链表同时为空才表示 same tree
return q == null && p == null;
}
return p.val == q.val && isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册