上一页 1 2 3 4 5 6 7 8 9 ··· 11 下一页
方法一:最简单的方法是将列表中的数字存储在vector中,那么方法同上 方法二:基于列表遍历的方式,这里需要注意当遍历右子树时,lt=0而不是mid+1; Read More
posted @ 2017-04-17 20:42 chengcy Views(116) Comments(0) Diggs(0)
方法:使用递归的方式 Read More
posted @ 2017-04-17 19:43 chengcy Views(110) Comments(0) Diggs(0)
方法一:使用递归的方式直接进行判断,也即对于每个节点,其值需要大于左子树最大节点,小于右子树最小节点,但这种方法在leetcode中不能accepted,因为测试集中节点的值有INT_MIN和INT_MAX。。。 对于上面方法,更简单的写法如下: 方法二:采用中序遍历的方式,若遍历得到的结果呈递增顺 Read More
posted @ 2017-04-16 18:45 chengcy Views(111) Comments(0) Diggs(0)
方法:这里使用递归的方式 Read More
posted @ 2017-04-16 17:08 chengcy Views(110) Comments(0) Diggs(0)
这里需要总结规律: f(0)=f(1)=1; f(2)=f(0)*f(1) + f(1)*f(0) f(3)=f(0)*f(2) + f(1)*f(1) + f(2)*f(0) Read More
posted @ 2017-04-16 12:05 chengcy Views(87) Comments(0) Diggs(0)
方法和依据前序和中序遍历确定二叉树一致。 Read More
posted @ 2017-04-16 11:19 chengcy Views(140) Comments(0) Diggs(0)
这里使用递归的算法,特别需要递归中边界的判断 Read More
posted @ 2017-04-16 11:00 chengcy Views(105) Comments(0) Diggs(0)
以下两种方法均适用于任意结构的树 方法一:使用栈的数据结构 方法二:基于层次遍历的方法,使用指针记录下一层首先遍历的节点 Read More
posted @ 2017-04-15 18:00 chengcy Views(131) Comments(0) Diggs(0)
方法一:采用递归的方法 方法二:采用给非递归的方法,基于栈数据结构 Read More
posted @ 2017-04-15 17:07 chengcy Views(143) Comments(0) Diggs(0)
方法一:使用递归的方法,使用一个变量记录以当前节点的左右节点为根节点的子树是否是平衡树,同时根据树的深度判断当前树是否为平衡树。 Read More
posted @ 2017-04-15 16:31 chengcy Views(75) Comments(0) Diggs(0)
上一页 1 2 3 4 5 6 7 8 9 ··· 11 下一页