Skip to content

Commit 9e8db0a

Browse files
committed
Runtime: 102 ms (Top 35.16%) | Memory: 42.5 MB (Top 44.08%)
1 parent 644eade commit 9e8db0a

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Runtime: 102 ms (Top 35.16%) | Memory: 42.5 MB (Top 44.08%)
12
/**
23
* @param {number[]} prices
34
* @return {number}
@@ -6,17 +7,17 @@ var maxProfit = function(prices) {
67
let lowestNum = prices[0];
78
let highestNum = prices[0];
89
let profit = highestNum - lowestNum;
9-
10+
1011
for(var indexI=1; indexI<prices.length; indexI++) {
11-
if(prices[indexI] < prices[indexI - 1]) {
12-
lowestNum = prices[indexI];
12+
if(prices[indexI] < prices[indexI - 1]) {
13+
lowestNum = prices[indexI];
1314
}
14-
if(prices[indexI] > lowestNum) {
15+
if(prices[indexI] > lowestNum) {
1516
lowestNum = prices[indexI - 1];
1617
profit = profit + prices[indexI] - lowestNum;
17-
highestNum = prices[indexI];
18+
highestNum = prices[indexI];
1819
}
1920
}
20-
21+
2122
return profit;
22-
};
23+
};

0 commit comments

Comments
 (0)