https://oj.leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/http://blog.csdn.net/linhuanmars/article/details/23164149publicclassSolution{
publicintmaxProfit(int[]prices){
//Ifasmanytransactions
//Gready
intpro=0;
intbuy=0;
booleanhold=false;
int..
分类:
其他好文 时间:
2015-01-06 18:13:23
阅读次数:
132
https://oj.leetcode.com/problems/best-time-to-buy-and-sell-stock/http://blog.csdn.net/linhuanmars/article/details/23162793publicclassSolution{
publicintmaxProfit(int[]prices)
{
//SolutionA:
returnmaxProfit_DP(prices);
//SolutionB:
//returnmaxProfit_Binary(..
分类:
其他好文 时间:
2015-01-06 18:11:55
阅读次数:
176
Say you have an array for which the ith element is the price of a given stock on day i.
Design an algorithm to find the maximum profit. You may complete at most two transactions.
Note:
You may ...
分类:
其他好文 时间:
2015-01-06 15:41:54
阅读次数:
189
Say you have an array for which the ith element is the price of a given stock on day i.
Design an algorithm to find the maximum profit. You may complete at most two transactions.
Note:
You may ...
分类:
其他好文 时间:
2015-01-04 17:14:20
阅读次数:
130
Good for array and linked list. Stable Sort.Time Complexity: Best, Average, Worst => O(nlogn);Space Complexity: O(n), in-place merge sort makes it ver...
分类:
其他好文 时间:
2015-01-04 13:25:46
阅读次数:
156
Insertion Sort:Time Complexity: Best O(n) (when already sorted); Average O(n^2); Worst O(n^2).Space Complexity: O(1) public static void main(String...
分类:
其他好文 时间:
2015-01-04 11:15:10
阅读次数:
249
经常在各种平台的online test里面不熟悉STDIN, STOUT,下面举个例子:另外一个例子:从system.in读取一行作为输入String, 得到返回结果之后把它写入到指定位置的文件当中1 Scanner sc = new Scanner(new File("myNumbers")).....
分类:
编程语言 时间:
2015-01-04 08:38:03
阅读次数:
185
虽然官方解释是这题目里的树看作无向无环图,从答案来看还是在“以1作为根节点”这一前提下进行的,这棵树搭建好以后,从叶节点开始访问,一直推到根节点即可——很像动态规划的“自底向上”。但这棵树的搭建堪忧:给出的边不知道哪边更接近根节点。所以我给出的方案干脆在两个顶点都将对方加成孩子,等到访问的时候再作处...
分类:
其他好文 时间:
2015-01-03 23:50:30
阅读次数:
233
原题大致上就是检测一系列进程之间是否存在循环依赖的问题,形如: a->b->c->a, a->a ,都行成了循环依赖,事实上可以视为“检测链表中是否存在环”AC代码:#include #include #include using namespace std;int main(){ int p...
分类:
其他好文 时间:
2015-01-03 23:41:07
阅读次数:
199
Best Time to Buy and Sell StockSay you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to compl...
分类:
其他好文 时间:
2015-01-03 19:43:30
阅读次数:
205