leetcode 714 Best Time to Buy and Sell Stock with Transaction Fee
2017-10-28 14:35
369 查看
class Solution { public int maxProfit(int[] prices, int fee) { int n=prices.length; if(prices==null||n==0) return 0; int[] buy=new int ; int[] sell=new int ; 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]); } }
相关文章推荐
- 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 (带有抛售费用的股票最大利润) -- medium
- 714. Best Time to Buy and Sell Stock with Transaction Fee。
- LeetCode 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] 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
- 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
- 714. Best Time to Buy and Sell Stock with Transaction Fee(M)
- LeetCode: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
- 714[Medium]: Best Time to Buy and Sell Stock with Transaction Fee