【LeetCode】Best Time to Buy and Sell Stock II
来源:互联网 发布:云杉网络 张天鹏 编辑:程序博客网 时间:2024/06/02 05:59
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 max = 0; int diff = 0; for(int i = 1; i < prices.size(); i++) { diff = prices[i] - prices[i-1]; if(diff > 0) max += diff; } return max; }};
0 0
- [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
- 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
- 【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
- [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
- [leetcode] Best Time to Buy and Sell Stock II
- python strip()函数
- HDU 1874 畅通工程续 最短路
- 博客第一天
- Android获取明天日期
- hdu 3478 Catch
- 【LeetCode】Best Time to Buy and Sell Stock II
- 考数据库系统会用到的一些计算方法和题目整理(1)
- Linux Input子系统之第一篇(input_dev/input_handle/input_handler)
- Windows系统配置PHP+Apache
- 【OpenGL游戏开发之五】freetype2 显示汉字
- ubuntu下hello world kernel Module:MODPOST 0 modules
- Java synchronized详解
- linux下杀死进程全权讲解
- ECM EMM