Skip to content

Commit a2b0f9c

Browse files
refactor 121
1 parent a6f75dc commit a2b0f9c

File tree

1 file changed

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

1 file changed

+4
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ public int maxProfit(int[] prices) {
3333
if (prices == null || prices.length == 0) {
3434
return 0;
3535
}
36-
int buy = prices[0];
36+
int minBuy = prices[0];
3737
int maxProfit = 0;
3838
for (int i = 1; i < prices.length; i++) {
39-
if (prices[i] < buy) {
40-
buy = prices[i];
39+
if (prices[i] < minBuy) {
40+
minBuy = prices[i];
4141
} else {
42-
maxProfit = Math.max(maxProfit, prices[i] - buy);
42+
maxProfit = Math.max(maxProfit, prices[i] - minBuy);
4343
}
4444
}
4545
return maxProfit;

0 commit comments

Comments
 (0)