上一页 1 ··· 6 7 8 9 10 11 下一页
  2015年4月8日
摘要: Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 /3return [1,2,3].可用递归,进行。也可以用迭代... 阅读全文
posted @ 2015-04-08 22:10 黄瓜小肥皂 阅读(108) 评论(0) 推荐(0) 编辑
  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) 编辑
  2015年4月6日
摘要: 最容易想到的算法是除余法,继而考虑到除法的代价较高,而且除数是2,会想到使用向右移位来代替除法,并使用&0x1操作来取末位的值,这样提高了算法的效率。然而,这样仍然进行了63次&操作、63次移位操作和63次+操作。若假设字长大小不限,记作N,那么上述算法的时间复杂度都为O(N)。具体实现方法:1.除... 阅读全文
posted @ 2015-04-06 16:30 黄瓜小肥皂 阅读(1980) 评论(0) 推荐(0) 编辑
  2015年4月5日
摘要: Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as theHamming weight).For example, the 32-bit in... 阅读全文
posted @ 2015-04-05 23:02 黄瓜小肥皂 阅读(218) 评论(0) 推荐(0) 编辑
摘要: Related to questionExcel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example:A -> 1... 阅读全文
posted @ 2015-04-05 18:15 黄瓜小肥皂 阅读(153) 评论(0) 推荐(0) 编辑
摘要: I:Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transactio... 阅读全文
posted @ 2015-04-05 16:59 黄瓜小肥皂 阅读(148) 评论(0) 推荐(0) 编辑
摘要: Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical an... 阅读全文
posted @ 2015-04-05 00:32 黄瓜小肥皂 阅读(149) 评论(0) 推荐(0) 编辑
  2015年4月4日
摘要: Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest le... 阅读全文
posted @ 2015-04-04 21:12 黄瓜小肥皂 阅读(127) 评论(0) 推荐(0) 编辑
上一页 1 ··· 6 7 8 9 10 11 下一页