2015年4月7日
摘要: Given a linked list, determine if it has a cycle in it.Can you solve it without using extra space?每个节点再开辟一个属性存放是否访问过,这样遍历一遍即可知道是否有环。但为了不增加额外的空间,可以设置两个... 阅读全文
posted @ 2015-04-07 23:46 黄瓜小肥皂 阅读(141) 评论(0) 推荐(0) 编辑
摘要: Catalan数令h(1)=1,h(0)=1,catalan数满足递归式:h(n)= h(1)*h(n-1) + h(2)*h(n-2) + ... + h(n-1)h(1) (其中n>=2)另类递归式: h(n)=((4*n-2)/(n+1))*h(n-1);该递推关系的解为: h(n+1)... 阅读全文
posted @ 2015-04-07 22:37 黄瓜小肥皂 阅读(158) 评论(0) 推荐(0) 编辑
摘要: Givenn, how many structurally uniqueBST's(binary search trees) that store values 1...n?For example,Givenn= 3, there are a total of 5 unique BST's.注意:二... 阅读全文
posted @ 2015-04-07 21:45 黄瓜小肥皂 阅读(191) 评论(0) 推荐(0) 编辑