# leetCode 100. Same Tree 树

100. 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.

```/**
* Definition for a binary tree node.
* struct TreeNode {
*     int val;
*     TreeNode *left;
*     TreeNode *right;
*     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
bool isSameTree(TreeNode* p, TreeNode* q) {
bool childResult;
if( NULL == p && NULL == q)
return true;
if( NULL != p && NULL != q && p->val == q->val)
{
return childResult = isSameTree(p->left,q->left) && isSameTree(p->right,q->right);
}
return false;

}
};```

2016-08-07 00:01:38

## [leetcode] 100. 相同的树

100. 相同的树 判断两颗二叉树是否完全相同,把该树转变为数组展示形式, 前序遍历,然后看结果是否一致即可 class Solution { String s = ""; void dfs(TreeNode tree){ if (tree == null) return; s+=tree.val; if (tree.left!=null) dfs(tree.left); if (tree.right!=null) dfs(tree.right); } public boolean i

## LeetCode 100. 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.  题目标题:Tree 这道题目给了我们两个二叉树,让我们判断这两个二叉树是否一摸一样.利用preOrder 来遍历tree, 对于每

## 小程序 - leetcode 100. Same Tree

https://leetcode.com/problems/same-tree/ /** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ bool isSameTree(struct TreeNode* p, struct TreeNode* q) { if (p == NULL) retur

## leetcode 100. 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. 简单的递归. /** * Definition for a binary tree node. * struct TreeNode

## Leetcode 100. 相同的树（待整理）

1.题目描述 给定两个二叉树,编写一个函数来检验它们是否相同. 如果两个树在结构上相同,并且节点具有相同的值,则认为它们是相同的. 示例 1: 输入: 1 1 / \ / 2 3 2 3 [1,2,3], [1,2,3] 输出: true 示例 2: 输入: 1 1 / 2 2 [1,2], [1,null,2] 输出: false 示例 3: 输入: 1 1 / \ / 2 1 1 2 [1,2,1], [1,1,2] 输出: false 2.解法一:递归 3.解法二:非递归 4.问题转化:树