714. Best Time to Buy and Sell Stock with Transaction Fee
2017-12-28 10:55
513 查看
1、题目描述
输入一个数组表示股票价格,一个数字fee表示完成一次交易要交的fee,返回最大利润。
2、思路
与冷静一天那道题基本一样吧,就是不需要presell了。【309题】
3、代码
输入一个数组表示股票价格,一个数字fee表示完成一次交易要交的fee,返回最大利润。
2、思路
与冷静一天那道题基本一样吧,就是不需要presell了。【309题】
3、代码
int maxProfit(vector<int>& prices, int fee) { int buy = INT_MIN, sell = 0,prebuy; for(int i=0;i<prices.size();i++){ prebuy = buy; buy = max(buy,sell-prices[i]-fee); sell = max(sell,prebuy + prices[i]); } return sell; }
相关文章推荐
- 714[Medium]: Best Time to Buy and Sell Stock with Transaction Fee
- 714. Best Time to Buy and Sell Stock with Transaction Fee
- 714. Best Time to Buy and Sell Stock with Transaction Fee
- 714. Best Time to Buy and Sell Stock with Transaction Fee
- LeetCode-714:Best Time to Buy and Sell Stock with Transaction Fee (带有抛售费用的股票最大利润) -- medium
- 714. Best Time to Buy and Sell Stock with Transaction Fee
- 714. Best Time to Buy and Sell Stock with Transaction Fee。
- leetcode 714 Best Time to Buy and Sell Stock with Transaction Fee
- 714. Best Time to Buy and Sell Stock with Transaction Fee
- Best Time to Buy and Sell Stock with Transaction Fee[LeetCode 714]
- 714. Best Time to Buy and Sell Stock with Transaction Fee
- 714. Best Time to Buy and Sell Stock with Transaction Fee
- 714. Best Time to Buy and Sell Stock with Transaction Fee
- LeetCode 714 Best Time to Buy and Sell Stock with Transaction Fee
- Leetcode算法学习日志-714 Best Time to Buy and Sell Stock with Transaction Fee
- 714. Best Time to Buy and Sell Stock with Transaction Fee(M)
- 714. Best Time to Buy and Sell Stock with Transaction Fee
- LeetCode算法问题10 —— Best Time to Buy and Sell Stock with Transaction Fee
- Best Time to Buy and Sell Stock with Transaction Fee
- 【12月19日】LeetCode刷题日志(三):Best Time to Buy and Sell Stock with Transaction Fee