本周的基础巩固2训练了基础数据结构:队列,链表,树,图,以及DFS和BFS算法等。下面总结一下一些需要注意的地方。
数据结构结构基础中树是一个难点,因为树的定义就是递归的,因此解决和树有关的问题总是从递归的思想上去考虑。树的结构中最常见的是二叉树,二叉树自身有很多独特的数学特性,因此题目中经常见到这种树,比如本次训练的E题,利用的就是二叉树叶子结点i的深度depth与总结点数的关系:1先解决边界...
分类:
其他好文 时间:
2015-04-05 16:09:24
阅读次数:
130
判断一个二叉树是否为平衡二叉树
int Depth(BinTree* root)
{
if(root == NULL)
return 0;
return max(Depth(root->left),Depth(root->right))+1;
}
bool isBalancedBinTree(BinTree* root)
{
if(root ==NULL)
return 1;
i...
分类:
其他好文 时间:
2015-04-05 12:02:53
阅读次数:
104
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest le...
分类:
其他好文 时间:
2015-04-04 22:22:21
阅读次数:
229
LeetCode104:Maximum Depth of Binary TreeGiven a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path fr...
分类:
其他好文 时间:
2015-04-04 11:52:56
阅读次数:
93
1 import java.util.*; 2 3 public class Slots6_21 { 4 final static int DEPTH = 10; 5 6 public static void main(String[] args) { 7 Sc...
分类:
编程语言 时间:
2015-04-03 13:22:11
阅读次数:
127
1.题目描述:点击打开链接
2.解题思路:本题利用dfs解决,不过思维上要发挥一些创造性。本题问至少要修改的砝码个数,那么首先可以想到要选一个基准砝码,其他所有的砝码都试图根据这个基准法吗而改变。不过本题的巧妙之处就在这里,只要以深度为depth(depth从0开始)重量为w的砝码为基准,那么就能求出整个天平的总重量,即w*2^(depth),在代码中可以简洁地表示为wth。这样,我们只用统计每...
分类:
其他好文 时间:
2015-04-01 15:26:38
阅读次数:
112
题目:Given a binary tree, determine if it is height-balanced.
For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1....
分类:
其他好文 时间:
2015-03-30 16:24:02
阅读次数:
129
du命令 查看当前目录下的所有目录及子目录的大小 [root@121?redis-2.8.19]#?du?-h?. -h表示用K、M、G的人性化形式显示 [root@121?redis-2.8.19]#?du?-h?--max-depth=1?. [root@121?redis-2.8.19]#?du?...
分类:
其他好文 时间:
2015-03-30 13:30:25
阅读次数:
135
js 的一些小技巧(1)传入一个表单控件(如input输入框,按钮)获取所在的formvar getForm= function (formElement) {
var $that=$(formElement).parent();
var max=6;//limit the depth
var fieldsetElement=n...
分类:
Web程序 时间:
2015-03-28 11:38:01
阅读次数:
215
mysql 1030 Got error 28 from storage engine 错误原因:磁盘临时空间不够。解决办法:df -h 查看设备存储的使用情况 du -h --max-depth=1 查看目录的大小,删除一部分内容
分类:
数据库 时间:
2015-03-21 22:53:01
阅读次数:
197