122. Best Time to Buy and Sell Stock II
来源:互联网 发布:暴力营销软件 编辑:程序博客网 时间:2024/06/05 07:58
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).
class Solution {public: int maxProfit(vector<int>& prices) { if (prices.size() == 0) return 0; int sum = 0; for(int i = 0; i < prices.size() - 1; i ++) { if(prices[i] < prices[i + 1]) { sum += prices[i + 1] - prices[i]; } } return sum; }};
0 0
- 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
- MBCS,UNICODE,UTF-8之间的转换
- 多线程 生产者消费者模式 线程之间的通讯问题
- All packages are not available for download! The following packages are not available:
- 活动选择
- Java中将字符串变成字符(字节)串,并且遍历的两种方法
- 122. Best Time to Buy and Sell Stock II
- 文件压缩
- getElementById与IE6
- Flutter基础—你好,Flutter!
- Linux下配置JDK
- MyBatis新增时的序列主键
- leetcode---Third Maximum Number
- dubbo进阶--管控台
- 快速记录一下cocos2dx 3.x 全屏幕 blur 效果实现相关代码