摘要:
Given a linked list, determine if it has a cycle in it.Can you solve it without using extra space?每个节点再开辟一个属性存放是否访问过,这样遍历一遍即可知道是否有环。但为了不增加额外的空间,可以设置两个... 阅读全文
摘要:
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)... 阅读全文
摘要:
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.注意:二... 阅读全文