[LeetCode] Best Time to Buy and Sell Stock II
来源:互联网 发布:c语言点餐系统 编辑:程序博客网 时间:2024/06/09 23:24
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 sum = 0; int sz = prices.size(); for(int i = 0; i < sz - 1; i++) { if(prices[i+1] - prices[i] > 0) sum += prices[i+1] - prices[i]; } return sum; }};
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
- 《算法导论》笔记 第21章 总结与思考
- [LeetCode] Best Time to Buy and Sell Stock
- C语言基础—复杂数据类型
- SVN控制参考文章
- LeetCode Unique Paths
- [LeetCode] Best Time to Buy and Sell Stock II
- 免费80端口穿透之nat123端口映射原理及使用方法
- UVA 10453 Make Palindrome(区间简单DP)
- 笔记之Prolog
- MySQL报错处理
- python 安装django
- native wifi mac rssi
- [LeetCode] Best Time to Buy and Sell Stock III
- 大道至简 悟在天成