LeetCode之maxProfitII
来源:互联网 发布:销售软件零税率 编辑:程序博客网 时间:2024/06/16 04:52
解法一:
int maxprofit2(vector<int> &prices) //Best Time to Buy and Sell Stock II {//cout<<prices[0];if (prices.size()==0||prices.size()==1){return 0;}int i=0,j=0,profit=0;while (prices[i]>=prices[i+1]){i++;if (i>=prices.size()-1){return 0;}}//i--;profit-=prices[i];while(prices[i]<=prices[i+1]) {i++;if (i>=prices.size()-1){return profit+=prices[i];}}profit+=prices[i];vector<int> sub_prices;for (j=i+1;j<=prices.size()-1;j++){sub_prices.push_back(prices[j]);}profit+=maxprofit2(sub_prices);return profit;}
解法二:
int maxprofit2(vector<int> &prices) //Best Time to Buy and Sell Stock II {//cout<<prices[0];if (prices.size()==0||prices.size()==1){return 0;}int i=0,j=0,profit=0;while (prices[i]>=prices[i+1]){i++;if (i>=prices.size()-1){return 0;}}//i--;profit-=prices[i];while(prices[i]<=prices[i+1]) {i++;if (i>=prices.size()-1){return profit+=prices[i];}}profit+=prices[i];vector<int> sub_prices;for (j=i+1;j<=prices.size()-1;j++){sub_prices.push_back(prices[j]);}profit+=maxprofit2(sub_prices);return profit;}
0 0
- LeetCode之maxProfitII
- LeetCode 之
- LeetCode之Surrounded Regions
- LeetCode之Palindrome Partitioning
- LeetCode之Word Ladder
- leetcode之Same Tree
- leetcode之sqrt(x)
- leetcode之atoi
- leetcode之Reverse Integer
- leetcode之subsets
- leetcode之Path Sum
- leetcode之same tree
- leetcode之Plus One
- leetcode之Palindrome Partitioning
- leetcode之Valid Palindrome
- leetcode之Edit Distance
- leetcode之Gray code
- leetcode之Two Sum
- Android android下的数据持久化和读取数据,保存数据到手机及SD卡
- ubuntu12.04安装openCV2.4.2
- 测试覆盖率
- ubuntu 10.10 apt-get 源
- PHP汉字拼音转换和公历农历转换
- LeetCode之maxProfitII
- 递归爬楼梯
- svn回到历史的某个版本--转
- 小技巧(持续更新)
- eye closure detection using flandmark toolbox
- android应用面试宝典;footerview自动添加在下翻页的最后一项;主界面返回键退出提示
- About_C_003
- uva 11589 - Save the President(暴力)
- 【小白笔记】PHP学习之路 (20) --类的初始化、析构函数与继承