param { number [ ] } prices return { number } function maxProfitOnce ( prices ) { let minPrice = Infinity ; let maxProfit = 0 ; for ( let i = 0 ; i < prices . length ; i ++ ) { if ( prices [ i ] < minPrice ) { minPrice = prices [ i ] ; } else if ( prices [ i ] - minPrice > maxProfit ) { maxProfit = prices [ i ] - minPrice ; } } return maxProfit ; } param { number [ ] } prices return { number } function maxProfitMore ( prices ) { let profit = 0 ; for ( let i = 0 ; i < prices . length - 1 ; i ++ ) { if ( prices [ i + 1 ] - prices [ i ] > 0 ) { profit += prices [ i + 1 ] - prices [ i ] ; } } return profit ; } param { number [ ] } prices param { number } fee function maxProfitWithFee ( prices , fee ) { let cash = 0 ; let hold = - prices [ 0 ] ; for ( let i = 1 ; i < prices . length ; i ++ ) { cash = Math . max ( cash , hold + prices [ i ] - fee ) ; hold = Math . max ( hold , cash - prices [ i ] ) ; } return cash ; } export { maxProfitOnce , maxProfitMore , maxProfitWithFee } ;