用了DP的方法,还有hashtable 1 import java.util.*; 2 3
public class Solution { 4 public int climbStairs(int n) { 5 Hashtable table =
new Hashtable...
分类:
其他好文 时间:
2014-05-23 08:31:02
阅读次数:
234
一次过,空间复杂度为O(m+n), 下一次做的时候寻找constant space
solution。用boolean array也可以,用bit vector可能会更节省 1 import java.util.*; 2 3 public
class Solution { 4 public...
分类:
其他好文 时间:
2014-05-23 08:30:28
阅读次数:
278
Given an input string, reverse the string word
by word.For example,Given s = "the sky is blue",return "blue is sky the". 1
Class Solution{ 2 public: ....
分类:
其他好文 时间:
2014-05-23 02:59:21
阅读次数:
260
这几个题很典型也是国外一些知名公司经常会问到的题
3Sum:
排序,避免重复,时间复杂度O(n^2)
class Solution {
public:
vector > threeSum(vector &num) {
int len=num.size();
sort(num.begin(),num.begin()+len);...
分类:
其他好文 时间:
2014-05-22 17:25:02
阅读次数:
259
首先要肯定的一点是,在一个解决方案(solution)中是可以添加多个项目(project)的,这多个项目之间存在两种关系:1.项目间彼此独立,各自有各自的入口,只是组织在一个解决方案中便于管理;2.项目间存在相互调用,只存在一个入口。
在这里先讨论一下第一种关系。 项目间彼此独立,每个项目...
分类:
其他好文 时间:
2014-05-22 16:34:33
阅读次数:
234
Reverse digits of an integer.Example1:x = 123,
return 321Example2:x = -123, return -321 1 class Solution { 2 public: 3 int
reverse(int x) { 4 ...
分类:
其他好文 时间:
2014-05-22 16:26:23
阅读次数:
165
class Solution {public: int maxProfit(vector
&prices) { int len = prices.size(); if (len maxv) { maxv = cur; ...
分类:
其他好文 时间:
2014-05-22 05:09:49
阅读次数:
256
Visual
Studio中的Build和Rebuild区别一般来说Rebuild=99%*(Clean+Build),效果在非常小的可能性下会不同,一般可以忽略。Rebuild是对Solution下的所有项目,逐个进行
Clean+Build。不论文件更改与否Clean+Build是对选中的项目(...
分类:
其他好文 时间:
2014-05-21 22:07:46
阅读次数:
312
Two elements of a binary search tree (BST) are
swapped by mistake.Recover the tree without changing its structure.Note:A
solution using O(n) space is ...
分类:
其他好文 时间:
2014-05-21 19:11:16
阅读次数:
266
题意:现在有一群人,告诉你每个人都认识哪些人,让你将这一群人分成两组,其中每一组中的每个人都相互认识,并且使得两组中的人数尽量相近。问你是否能分成这样两组,如果不能输出No
Solution ,否则输出人数最相近的方案。 注意你认识我不代表我认识你,组中的每一个人都必须是相互认识的。 首先建立由人和...
分类:
其他好文 时间:
2014-05-21 05:04:15
阅读次数:
306