方法一:使用递归的方式直接进行判断,也即对于每个节点,其值需要大于左子树最大节点,小于右子树最小节点,但这种方法在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)