122. Best Time to Buy and Sell Stock II
来源:互联网 发布:c语言是解释型语言吗 编辑:程序博客网 时间:2024/06/06 12:36
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 res=0,len=prices.size(); for(int i=0;i<len-1;i++){ if(prices[i+1]>prices[i]) res+=prices[i+1]-prices[i]; } return res; }};mdzz...
阅读全文
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
- 【矩阵的乘法和加法模板】
- HDU 6118 度度熊的交易计划 最小费用可行流
- 【第7章】像高手一样玩转数据
- bootstrap-select下拉搜索插件 动态加载自己数据的二级联动
- iOS App启动流程
- 122. Best Time to Buy and Sell Stock II
- 113. Path Sum II
- HDU6119 小小粉丝度度熊(区间)
- 【jquery】解决轮播图鼠标快速移入移出导致bug思路
- UVA
- SQL注入之GET型常规注入
- 通过父元素无视动态dom节点给元素挂事件
- 单源最短路(Dijkstra)邻接表实现
- js中==和===的区别