摘要: Objective:Find out the lowest point to buy-in and find out the a following hightest point to sell-out. And the maximal profit is equivalent to the max difference between the highest point and lowest point.Before solving this problem, suggest referring to the "maximum subarray" first. Then 阅读全文
posted @ 2013-10-17 02:33 WinsCoder 阅读(160) 评论(0) 推荐(0) 编辑
摘要: Code:class Solution {public: int maxDep; vectorbuf; vector> res; void dfs(int dep, vector &valid, vector &num){ if(dep==maxDep){ res.push_back(buf); return; } for(int i=0;i> permuteUnique(vector &num) { buf.clear(); res.clear(); ... 阅读全文
posted @ 2013-10-17 02:03 WinsCoder 阅读(150) 评论(0) 推荐(0) 编辑
摘要: 题目:输入一个整型数组,数据元素有正数也有负数,求元素组合成连续子数组之和最大的子数组,要求时间复杂度为O(n)。例如:输入的数组为1, -2,3, 10, -4, 7, 2, -5,最大和的连续子数组为3, 10, -4, 7, 2,其最大和为18。背景:本题最初为2005年浙江大学计算机系考研题的最后一道程序设计题,在2006年里包括google在内的很多知名公司都把本题当作面试题。由于本题在网络中广为流传,本题也顺利成为2006年程序员面试题中经典中的经典。分析:如果不考虑时间复杂度,我们可以枚举出所有子数组并求出他们的和。不过非常遗憾的是,由于长度为n的数组有O(n2)个子数组(即:n 阅读全文
posted @ 2013-10-17 00:58 WinsCoder 阅读(254) 评论(0) 推荐(0) 编辑