Leetcode:714. Best Time to Buy and Sell Stock with Transaction Fee
来源:互联网 发布:竞彩代购软件 编辑:程序博客网 时间:2024/05/21 14:08
c++:
class Solution {public: int maxProfit(vector<int>& prices, int fee) { int len = prices.size(); vector<int> maxProfit(len), cashWhenHoldOne(len); maxProfit[0] = 0, cashWhenHoldOne[0] = -prices[0]; for (int i = 1; i < len; i++) { maxProfit[i] = max(maxProfit[i-1], cashWhenHoldOne[i-1] + prices[i] - fee); cashWhenHoldOne[i] = max(cashWhenHoldOne[i-1], maxProfit[i-1] - prices[i]); } return maxProfit[len-1]; }};
阅读全文
0 0
- [LeetCode] Algorithms-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
- [LeetCode]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
- Leetcode: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
- [leetcode] 714. Best Time to Buy and Sell Stock with Transaction Fee
- Best Time to Buy and Sell Stock with Transaction Fee
- Best Time to Buy and Sell Stock with Transaction Fee
- 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
- LeetCode #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[LeetCode 714]
- Linux:网络编程
- 数据结构之队列queue
- 编写多线程程序,模拟多个人通过一个山洞。
- Javascript学习笔记(console对象)
- python 学习笔记 9 -- Python强大的自省简析
- Leetcode:714. Best Time to Buy and Sell Stock with Transaction Fee
- dubbo--1.系统架构
- Spring核心理解
- 中北大学NUC2017新生赛1004/NOJ-1984
- ExtJs xtype的使用
- 欢迎使用CSDN-markdown编辑器
- html学习 -4
- 基于 HTML5 Canvas 的 3D 碰撞检测
- Leetcode:741. Cherry Pickup