题目:Count Complete Tree NodesGiven acompletebinary tree, count the number of nodes.Definition of a complete binary tree fromWikipedia:In a complete bin...
分类:
其他好文 时间:
2015-07-02 22:25:05
阅读次数:
170
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class...
分类:
其他好文 时间:
2015-07-02 19:31:46
阅读次数:
97
称号Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum....
分类:
其他好文 时间:
2015-07-02 19:21:40
阅读次数:
98
Given a binary search tree, write a function kthSmallest to find the
kth smallest element in it.
Note:
You may assume k is always valid, 1 ≤ k ≤ BST's total elements.
Follow up:
What if the BST...
分类:
其他好文 时间:
2015-07-02 15:50:38
阅读次数:
178
Given a complete binary tree, count the number of nodes.
Definition of a complete binary tree from Wikipedia:
In a complete binary tree every level, except possibly the last, is completely fille...
分类:
其他好文 时间:
2015-07-02 15:47:37
阅读次数:
119
废话不多说,直接上代码,哈哈,痛快:/**
* 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
https://leetcode.com/problems/kth-smallest-element-in-a-bst/Given a binary search tree, write a functionkthSmallestto find thekth smallest element in ...
分类:
其他好文 时间:
2015-07-02 11:58:59
阅读次数:
190
有三点收获:
第一:string类型的变量可以直接相互赋值。
第二:begin()-1在本地VS2012会出现运行时错误迭代器错误,而在leetcode在先提交时并没有出现错误。
第三:反转string类型变量,直接如下使用即可:
reverse(reversedResult.begin(), reversedResult.end());头文件并不需要添加。
下面是程序代码#include...
分类:
其他好文 时间:
2015-07-02 10:13:28
阅读次数:
96
Given a binary search tree, write a function kthSmallest to find the kth
smallest element in it.
Note:
You may assume k is always valid, 1 ≤ k ≤ BST's total elements.
Follow up:
What if the...
分类:
其他好文 时间:
2015-07-02 10:09:45
阅读次数:
110
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area.
For example, given the following matrix:
1 0 1 0 0
1 0 1 1 1
1 1 1 1 1
1 0 0 1 0
...
分类:
其他好文 时间:
2015-07-02 10:07:01
阅读次数:
115