1.题目描述
Given two binary trees, write a function to check if they are the same or not.
Two binary trees are considered the same if they are structurally identical and the nodes have the same value.
给定两个二叉树,编写一个函数来检验它们是否相同。
如果两个树在结构上相同,并且节点具有相同的值,则认为它们是相同的。
Example 1:
1 | Input: 1 1 |
Example 2:
1 | Input: 1 1 |
Example 3:
1 | Input: 1 1 |
2.Solutions
1 | public boolean isSameTree(TreeNode p, TreeNode q) { |