Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Runtime: 5 ms, faster than 82.93% of Java online submissions for Best Time to Buy and Sell Stock with Transaction Fee.
- // Memory Usage: 51.7 MB, less than 100.00% of Java online submissions for Best Time to Buy and Sell Stock with Transaction Fee.
- class Solution {
- public int maxProfit(int[] prices, int fee) {
- int profit = 0;
- int sell = 0;
- for (int i = prices.length - 1; i >= 0; i--) {
- int profitNew = Math.max(profit, sell - prices[i] - fee);
- sell = Math.max(sell, prices[i] + profit);
- profit = profitNew;
- }
- return profit;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement