Skip to content

Commit 0c8f109

Browse files
committed
update 121.best-time-to-buy-and-sell-stock.java
1 parent 8b238f6 commit 0c8f109

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

121.best-time-to-buy-and-sell-stock.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ public int maxProfit(int[] prices) {
8484
// Look for a lower price point for buying
8585
if (curr < buy) {
8686
buy = curr;
87-
} else {
88-
profit = Math.max(profit, curr - buy);
87+
} else if (curr - buy > profit) {
88+
profit = curr - buy;
8989
}
9090
}
9191

0 commit comments

Comments
 (0)