Skip to content

Commit 0bffc19

Browse files
committed
8 nov
1 parent 64b8d86 commit 0bffc19

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Blind 75

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,13 @@ class Twopointer{
172172
}
173173

174174
class SlidingWindow{
175-
maxProfit = function (prices) { // Best time to buy and sell stocks
176-
let maxProfit = 0; // no profit
177-
let minPrice = Infinity; // highest price
178-
for (let price=0; price < prices.length; price++) { // look for every price
179-
minPrice = Math.min(minPrice, price); // compare cuurent price with minimum price
180-
const profit = price - minPrice; // find current profit
181-
maxProfit = Math.max(maxProfit, profit); // compare current profit with maximum profit
175+
maxProfit = function(prices) { // Best time to buy and sell stocks
176+
let maxProfit = 0;
177+
let minPrice = Infinity;
178+
for (let price of prices){
179+
minPrice = Math.min(minPrice, price);
180+
const profit = price - minPrice;
181+
maxProfit = Math.max(maxProfit, profit);
182182
}
183183
return maxProfit;
184184
};

0 commit comments

Comments
 (0)