LeetCode题解-Best Time to Buy and Sell Stock II
来源:互联网 发布:淘宝上新抢拍怎么快 编辑:程序博客网 时间:2024/06/06 03:06
在Best Time to Buy and Sell Stock 基础上添加了新的条件: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).即:可以多次交易,但是手中只能有一只股票。
结题思路:只要有差价,即买入卖出(低买高卖)
代码如下:
<span style="font-family:KaiTi_GB2312;font-size:18px;">int maxProfit(vector<int>& prices) { int size=prices.size();if(size<=1)return 0;int sum=0;for (int i=1;i<size;i++)if(prices[i-1]<prices[i])sum+=prices[i]-prices[i-1];return sum; }</span>
0 0
- LeetCode题解-Best Time to Buy and Sell Stock II
- LeetCode题解:Best Time to Buy and Sell Stock II
- LeetCode 121. Best Time to Buy and Sell Stock & 122. Best Time to Buy and Sell Stock II题解
- LeetCode122. Best Time to Buy and Sell Stock II题解
- LeetCode - Best Time to Buy and Sell Stock III 题解
- LeetCode题解-Best Time to Buy and Sell Stock
- LeetCode题解-Best Time to Buy and Sell Stock III
- LeetCode题解:Best Time to Buy and Sell Stock
- LeetCode题解:121. Best Time to Buy and Sell Stock
- Leetcode题解 121. Best Time to Buy and Sell Stock
- LeetCode 121 Best Time to Buy and Sell Stock题解
- 【LeetCode题解】121. Best Time to Buy and Sell Stock
- LeetCode题解:121. Best Time to Buy and Sell Stock
- [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
- 从MySQL Bug#67718浅谈B+树索引的分裂优化
- HashMap的面试题
- LeetCode 108. Convert Sorted Array to Binary Search Tree
- C++之运算符重载(1)
- hdu 1556 Color the ball 【树状数组:区间修改、单点求值】
- LeetCode题解-Best Time to Buy and Sell Stock II
- 给你的python安个窝
- iOS代理模式与事件模型对比实现
- HDU 2044 一只小蜜蜂...
- 虚拟内存、物理内存
- SpringMVC视图解析器
- 【Java】Java reflection
- Android 之修改标题栏(title)
- HDU 1880 魔咒词典