714. Best Time to Buy and Sell Stock with Transaction Fee
Last updated
Last updated
/**
* Time complexity :
* Space complexity :
*/
class Solution {
public int maxProfit(int[] prices, int fee) {
int stock = Integer.MIN_VALUE, cash = 0;
for(int price: prices) {
stock = Math.max(stock, cash-price);
cash = Math.max(cash, stock+price-fee);
}
return cash;
}
}