1、题目名称 Same Tree(判断两棵树是否相等) 2、题目地址 https://leetcode.com/problems/same-tree/ 3、题目内容 英文:Given two binary trees, write a function to check if they are equal or not. Two b...
分类:
其他好文 时间:
2015-08-12 23:43:01
阅读次数:
147
【100-Same Tree(两棵树是否相同)】【LeetCode-面试算法经典-Java实现】【所有题目目录索引】原题 Given two binary trees, write a function to check if they are equal or not.
Two binary trees are considered equal if they are structural...
分类:
编程语言 时间:
2015-08-07 08:18:10
阅读次数:
185
题目: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...
分类:
其他好文 时间:
2015-08-02 08:55:40
阅读次数:
114
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x...
分类:
其他好文 时间:
2015-07-28 17:27:48
阅读次数:
85
题意:怎么判断两个二叉树相同思路:递归,值得注意的······需要判断树是否为空,否则会报超时的错····为什么是超时呢····奇怪代码:bool isSameTree(TreeNode* p, TreeNode* q) { if(p == NULL && q == NULL) ...
分类:
其他好文 时间:
2015-07-11 22:42:30
阅读次数:
131
题意:如题思路:递归解决,同判断对称树的原理差不多。先保证当前两个结点是相等的,再递归保证两左结点是相等的,再递归保证右结点是相等的。 1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int ...
分类:
其他好文 时间:
2015-07-10 00:08:15
阅读次数:
243
解法一:递归 1 bool isSameTree(TreeNode* p, TreeNode* q) 2 { 3 if (p == NULL && q == NULL) 4 return true; 5 if ((p == NULL && q != NULL) || ...
分类:
其他好文 时间:
2015-07-05 19:55:23
阅读次数:
97
废话不多说,直接上代码,哈哈,痛快:/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL)...
分类:
其他好文 时间:
2015-07-02 14:10:48
阅读次数:
91
#83 Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once.
For example,
Given 1->1->2, return 1->2.
Given 1->1->2->3->3...
分类:
其他好文 时间:
2015-06-24 19:01:53
阅读次数:
123
反转二叉树:
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
...
分类:
其他好文 时间:
2015-06-21 13:12:18
阅读次数:
147