Skip to content

Commit cfd7b05

Browse files
refactor 714
1 parent 9e8957b commit cfd7b05

File tree

1 file changed

+2
-2
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+2
-2
lines changed

src/main/java/com/fishercoder/solutions/_714.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ public int maxProfit(int[] prices, int fee) {
4040
int cash = 0;
4141
int hold = -prices[0];
4242
for (int i = 1; i < prices.length; i++) {
43-
cash = Math.max(cash, hold + prices[i] - fee);
44-
hold = Math.max(hold, cash - prices[i]);
43+
cash = Math.max(cash, hold + prices[i] - fee);//this means to sell the stock: gain the current ith day's price and pay the transaction fee
44+
hold = Math.max(hold, cash - prices[i]);//this means to buy in this stock on the ith day's price.
4545
}
4646
return cash;
4747
}

0 commit comments

Comments
 (0)