Inspired by DonaldTrump


  • 0
    W

    ''' public int maxProfit(int[] prices, int fee) {

           int L = prices.length; 
        
        if (L<=1)
            return 0; 
        
        int best_have = -prices[0] ;
        int best_havenot = 0;
        
        for (int i=1; i< L; i++)
            {
                int best_have_prev = best_have;
                int best_havenot_prev = best_havenot;
                best_have = Integer.max(best_havenot_prev - prices[i], best_have_prev); 
                best_havenot = Integer.max(best_havenot_prev, best_have_prev+prices[i]-fee);
            }
        
        return Integer.max(best_have, best_havenot);
        }'''

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.