leetcode 714 Best Time to Buy and Sell Stock with Transaction Fee
来源:互联网 发布:好玩的网络手游 编辑:程序博客网 时间:2024/05/21 10:54
class Solution { public int maxProfit(int[] prices, int fee) { int n=prices.length; if(prices==null||n==0) return 0; int[] buy=new int[n]; int[] sell=new int[n]; buy[0]=-prices[0];//假设第一天买入 sell[0]=0; for(int i=1;i<n;i++){ buy[i]=Math.max(buy[i-1],sell[i-1]-prices[i]); //今天是否买取决于等于昨天的买入的钱或者昨天卖出后的钱 sell[i]=Math.max(sell[i-1],buy[i-1]+prices[i]-fee); //今天是否卖取决于昨天卖出的钱和卖出后是否盈利 } return Math.max(buy[n-1],sell[n-1]); }}
阅读全文
0 0
- 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[LeetCode 714]
- 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算法问题10 —— Best Time to Buy and Sell Stock with Transaction Fee
- [LeetCode] Algorithms-714. Best Time to Buy and Sell Stock with Transaction Fee
- [LeetCode] DP之 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-Best Time to Buy and Sell Stock with Transaction Fee
- LeetCode: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
- MHA0.57+Centos7 +Mysql5.7 实现Mysql的高可用
- 算法学习(3):动态规划DP
- JQuerymobile实例源代码
- 一种微信直播H5直播与存储回放的HLS摄像机方案
- 16位遥感图像转8位显示 %2线性拉伸
- leetcode 714 Best Time to Buy and Sell Stock with Transaction Fee
- 计算机图形学-直线裁剪(Cohen-Sutherland编码裁剪算法)
- GPX转换为GP5
- MYSQL 子查询返回多列显示
- 重识计算机【一】——分类
- Understanding the JVM(四)对象的访问定位
- 利用matlab做回归分析
- ubuntu遇到了 dpkg was interrupted, you must manually run 'dpkg..的问题
- 机器人这步生死棋,英特尔是如何走的