递归实现当然太简单,也用不着为了ac走这种捷径吧。。非递归实现还挺有意思的。
树的非递归遍历一定要借助栈,相当于把原来编译器做的事情显式的写出来。对于中序遍历,先要访问最左下的节点,一定是进入循环后,不断的往左下走,走到不能走为止,这时候,可以从栈中弹出访问的节点,相当于“左根右”过程的“根”,然后应该怎么做呢?想一下中序遍历完根节点之后应该干嘛,对,是走到右子树中继续重复这个过程,但是有一点,...
分类:
其他好文 时间:
2014-05-09 14:57:08
阅读次数:
211
可能没想到简单方法的人,在上一题中就把这一题给做了。怎样把所有的树都生成出来呢?方法肯定用的是递归,但是有个致命的问题,如果做好了根节点再递归,那么出来的很多树都公用一个根节点,结果肯定是乱七八糟的。
怎么做?其实做法跟之前求个数在思想上是高度统一的,先把所有的左右子树都求出来,然后把它们之间的所有组合都连接到一个新建立出来的根节点,既然是分开左右子树,很容易想到类似二分的思想,每次指定的不是一...
分类:
其他好文 时间:
2014-05-09 14:13:55
阅读次数:
376
Path Sum IGiven 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 gi...
分类:
其他好文 时间:
2014-05-09 13:21:59
阅读次数:
320
筛选出 2012-2-1 的数据private DataTable GetData() {
DataTable dt = new DataTable(); dt.Columns.Add("Id", typeof(int)); ...
分类:
其他好文 时间:
2014-05-09 12:58:02
阅读次数:
259
If you ever had the problem where you need to
extract files from a SharePoint Content Database or normal SQL Database stored
as binary, this post will...
分类:
数据库 时间:
2014-05-09 09:54:59
阅读次数:
495
Given a binary tree, check whether it is a
mirror of itself (ie, symmetric around its center).For example, this binary tree
is symmetric: 1 / \ ...
分类:
其他好文 时间:
2014-05-09 09:28:18
阅读次数:
253
原文:如何扩展 Visual Studio 编辑器 在 Visual Studio 2010
的时代,扩展 Visual Studio 的途径有很多,开发者可以选择宏、Add-in、MEF 和 VSPackages进行自定义的扩展。但是宏在 Visual
Studio 2012 的时候被阉割了,Ad...
分类:
其他好文 时间:
2014-05-09 08:02:13
阅读次数:
532
这道题就是找规律啊!!!想想啊,11和10是可以连续的,那么10和11也是可以连续的。下面是AC代码:
1 /** 2 * The gray code is a binary numeral system where two successive values
differ in on...
分类:
其他好文 时间:
2014-05-09 07:38:17
阅读次数:
325
http://subclipse.tigris.org/update_1.8.x1,打开‘Help’->‘InstallnewSoftware’,点击"add"按钮,随便起个名字,把上面的url输入一下。2,在Subclipse下拉列表只选中Subclipse–RequiredSubversionClientAdapter–RequiredSubversionNativeLibraryAdapter(JavaHL)–St..
分类:
其他好文 时间:
2014-05-09 06:53:13
阅读次数:
236
$per_len=20000;//每次读多少字节$no_read_len=$content_len;//未读的字节(总字节大小)$str=‘‘;while($len<$content_len){$read=socket_read($socket,$per_len,PHP_BINARY_READ);$str.=$read;$len+=strlen($read);//总共读了多少字节}http://hi.baidu.com/cuttinger/item/..
分类:
Web程序 时间:
2014-05-09 06:45:59
阅读次数:
566