122. Best Time to Buy and Sell Stock II
来源:互联网 发布:淘宝一元捡漏 编辑:程序博客网 时间:2024/06/15 15:08
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 as many transactions as you like (ie, buy one and sell one share of the stock multiple times). However, you may not engage in multiple transactions at the same time (ie, you must sell the stock before you buy again).
class Solution
{
public:
int maxProfit(vector<int>& prices)
{
int len=prices.size();
if(len<=1)
return 0;
int sum(0);
int pro(0);
for(int i=1;i<len;i++)
{
if(prices[i]>prices[i-1])
pro=prices[i]-prices[i-1];
else
pro=0;
sum+=pro;
}
return sum;
}
};
- 122. Best Time to Buy and Sell Stock II
- LeetCode 122. Best Time to Buy and Sell Stock II
- 122.Best Time to Buy and Sell Stock II
- [Leetcode] 122. Best Time to Buy and Sell Stock II
- [leetcode] 122.Best Time to Buy and Sell Stock II
- 【leetcode】122.Best Time to Buy and Sell Stock II
- 122. Best Time to Buy and Sell Stock II
- 【LeetCode】122.Best Time to Buy and Sell Stock II
- [leetcode] 122. Best Time to Buy and Sell Stock II
- LeetCode #122. Best Time to Buy and Sell Stock II
- 122. Best Time to Buy and Sell Stock II LeetCode
- 122. Best Time to Buy and Sell Stock II
- 122. Best Time to Buy and Sell Stock II
- 122. Best Time to Buy and Sell Stock II
- [LeetCode]122. Best Time to Buy and Sell Stock II
- 122. Best Time to Buy and Sell Stock II
- Leetcode 122. Best Time to Buy and Sell Stock II
- leetcode 122. Best Time to Buy and Sell Stock II
- 【Android】这效果,我没法描述
- 图像和流媒体 -- 帧率、分辨率、码流的概念和关系
- 获取Java生成二维码所需要的Jar包(zxing方式)
- 虚拟机并行环境的安装
- hibernate04 持久化类和持久化对象
- 122. Best Time to Buy and Sell Stock II
- Solutions For Building 10G Home Network
- Developing Transactional Microservices Using Aggregates, Event Sourcing and CQRS
- 邻接表
- bzoj 1008
- 神技:压缩包转为图片
- Java 8中HashMap源码解析
- Google Guava学习(7)-Guava集合工具 Bimap接口
- VS2015 IIS Express 无法启动 解决办法