class Solution {
public int maxProfit(int[] prices, int fee) {
int[] sell=new int[prices.length];
int[] buy=new int[prices.length];
hold[0]=-prices[0];
for(int i=1;i<prices.length;i++){
sell[i]=Math.max(sell[i-1],hold[i-1]+prices[i]-fee);
hold[i]=Math.max(hold[i-1],sell[i-1]-prices[i]);
}
return Math.max(hold[prices.length-1],sell[prices.length-1]);
}
}
class Solution {
public int maxProfit(int[] prices, int fee) {
int sell=0;
int hold=-prices[0];
for(int i=1;i<prices.length;i++){
int temp=sell;
sell=Math.max(sell,hold+prices[i]-fee);
hold=Math.max(hold,temp-prices[i]);
}
return Math.max(hold,sell);
}
}