File tree Expand file tree Collapse file tree 1 file changed +7
-7
lines changed
Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Original file line number Diff line number Diff line change @@ -172,13 +172,13 @@ class Twopointer{
172172}
173173
174174class 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 };
You can’t perform that action at this time.
0 commit comments