Best Time to Buy and Sell Stock II
来源:互联网 发布:淘宝网如何刷单 编辑:程序博客网 时间:2024/06/07 00:52
题目:
Say you have an array for which the ith element is the price of a given stock on dayi.
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).
代码如下:
int maxProfit(vector<int> &prices) {
int n=prices.size();
if(n<=1)return 0;
int max=0;
for(int i=1;i<prices.size();i++)
{
if(prices[i]>prices[i-1])
max+=prices[i]-prices[i-1];
}
return max;
}
- [LeetCode]Best Time to Buy and Sell Stock II
- LeetCode Best Time to Buy and Sell Stock II
- Leetcode: Best Time to Buy and Sell Stock II
- [Leetcode] Best Time to Buy and Sell Stock II
- Best Time to Buy and Sell Stock II
- LeetCode : Best Time to Buy and Sell Stock II
- LeetCode Best Time to Buy and Sell Stock II
- [LeetCode] Best Time to Buy and Sell Stock II
- leetcode 61: Best Time to Buy and Sell Stock II
- [LeetCode] Best time to buy and sell a stock II
- Best Time to Buy and Sell Stock II
- Best Time to Buy and Sell Stock II
- 【leetcode】Best Time to Buy and Sell Stock II
- LeetCode - Best Time to Buy and Sell Stock II
- Best Time to Buy and Sell Stock II
- Best Time to Buy and Sell Stock II
- LeetCode之Best Time to Buy and Sell Stock II
- [LeetCode]Best Time to Buy and Sell Stock II
- linux驱动中的Timer和delay
- operamasks-ui使用笔记
- 移动 II
- Java多线程释放锁
- Windows Azure 提供更快的开发速度, 全球范围实现无与伦比的经济意义
- Best Time to Buy and Sell Stock II
- undofile故障恢复
- js 鼠标 移动 事件 获取 id
- 网页设计怎样最美?
- Dictironary<T> 绑定数据源
- oracle redo损坏的处理
- 编译原理学习周入门教程--(1)什么是编译程序?
- Linux 0.12 OS. math - math_emulate.c
- webbench tools