Best Time to Buy and Sell Stock II 买卖股票最好的时间II
来源:互联网 发布:数据库域 编辑:程序博客网 时间:2024/04/25 11:27
class Solution {
public:
//贪心法,低进高出,把所有正的价格差价相加起来。
int maxProfit(vector<int> &prices) {
int n=prices.size();
if(n<2)
return 0;
int profit=0;
int minbuy=prices[0];
for(int i=1;i<prices.size();i++)
{
if(prices[i]>prices[i-1])
profit+=prices[i]-prices[i-1];
}
return profit;
}
};
public:
//贪心法,低进高出,把所有正的价格差价相加起来。
int maxProfit(vector<int> &prices) {
int n=prices.size();
if(n<2)
return 0;
int profit=0;
int minbuy=prices[0];
for(int i=1;i<prices.size();i++)
{
if(prices[i]>prices[i-1])
profit+=prices[i]-prices[i-1];
}
return profit;
}
};
0 0
- Best Time to Buy and Sell Stock II 买卖股票最好的时间II
- 122. Best Time to Buy and Sell Stock II 最佳买卖股票的时间
- 【LintCode】 Best Time to Buy and Sell Stock II 买卖股票的最佳时机 II
- LintCode--best-time-to-buy-and-sell-stock-ii(买卖股票的最佳时机 II)
- Best Time to Buy and Sell Stock 买卖股票最好的时间
- Best Time to Buy and Sell Stock III 买卖股票的最好时间
- Best Time to Buy and Sell Stock 买卖股票的最好时间
- Best Time to Buy and Sell Stock II 多次买卖股票的最佳时机
- LeetCode OJ 之 Best Time to Buy and Sell Stock II (买卖股票的最佳时间 2)
- 150.Best Time to Buy and Sell Stock II-买卖股票的最佳时机 II(中等题)
- Best Time to Buy and Sell Stock II DP买卖股票
- Leetcode 122 Best Time to Buy and Sell Stock II 不限次数买卖股票最大收益
- Best Time to Buy and Sell Stock II 最佳时间买入卖出股票(多次买卖)@LeetCode
- [LeetCode]122. Best Time to Buy and Sell Stock II(最佳买卖时间 II)
- leetcode_122. Best Time to Buy and Sell Stock II 多次买卖股票,求交易的最大利润
- LeetCode OJ 之 Best Time to Buy and Sell Stock (买卖股票的最佳时间)
- [LeetCode] Best Time to Buy and Sell Stock IV 买卖股票的最佳时间之四
- Best Time to Buy and Sell Stock 【最佳买卖股票的时间】【容易】
- PCA人脸识别学习及C语言实现
- Memcached1.4.13(32、64位windows)在.Net中使用.zip
- 电脑内存常见问题处理方法
- javascript 对象Array详解
- SQL Server 2008 - Cannot set a credential for principal 'sa'.
- Best Time to Buy and Sell Stock II 买卖股票最好的时间II
- chapter 27 Calling C from Lua
- 子窗体显示在任务栏,且子窗体中又有弹窗
- String s=new String("123")创建了几个对象?
- VB.NET 串口异步访问
- 电脑内存常见问题处理方法
- 水仙
- MinGW 编译ffmpeg 1.2.1 的H.264 decoder
- jpa 分页和查询