122. Best Time to Buy and Sell Stock II
来源:互联网 发布:ipa版本淘宝的微淘 编辑:程序博客网 时间:2024/05/29 15:23
1、题目描述
股票交易。可以进行多次买卖,问最大利润是多少。
2、思路
只要prices[i]>prices[i-1],我就在利润里加上(prices[i]-prices[i-1])。换言之,
在一段时间内,股票一直是涨的,那么就在最开始买入,最后卖出。
3、代码
int maxProfit(vector<int>& prices) { int n = prices.size(); int ans=0; for(int i=0;i<n-1;i++){ if(prices[i+1]>prices[i]) ans+=(prices[i+1]-prices[i]); } return ans; }
阅读全文
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
- Sql查询空值结果参与运算
- nova流程图
- 算术表达式转四元式
- 前端笔记(一)
- adobe reader安装中断,无法安装卸载
- 122. Best Time to Buy and Sell Stock II
- java 接口调用memcached
- 单选框radio和复选框checkbox文字垂直居中问题
- SqueezeNet的Caffe实现
- python中的装饰器,函数带参数的装饰器,带类参数的装饰器
- leetcode 664. Strange Printer 奇怪的打印机 + 动态规划DP
- 如何用Python智能批量压缩图片?
- java注解开发
- YUV 转RGB公式说明