We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a6f75dc commit a2b0f9cCopy full SHA for a2b0f9c
src/main/java/com/fishercoder/solutions/_121.java
@@ -33,13 +33,13 @@ public int maxProfit(int[] prices) {
33
if (prices == null || prices.length == 0) {
34
return 0;
35
}
36
- int buy = prices[0];
+ int minBuy = prices[0];
37
int maxProfit = 0;
38
for (int i = 1; i < prices.length; i++) {
39
- if (prices[i] < buy) {
40
- buy = prices[i];
+ if (prices[i] < minBuy) {
+ minBuy = prices[i];
41
} else {
42
- maxProfit = Math.max(maxProfit, prices[i] - buy);
+ maxProfit = Math.max(maxProfit, prices[i] - minBuy);
43
44
45
return maxProfit;
0 commit comments