Skip to content

Commit 4c8e808

Browse files
add solution 121[js]
1 parent 3da9da7 commit 4c8e808

File tree

1 file changed

+13
-0
lines changed
  • solution/121.Best Time to Buy and Sell Stock

1 file changed

+13
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const maxProfit1 = function(prices){
2+
let min = prices[0];
3+
let profit = 0;
4+
for(let i = 0; i < prices.length; i++){
5+
if(prices[i] < min){
6+
min = prices[i];
7+
}
8+
if(profit < (prices[i] - min)){
9+
profit = prices[i] - min;
10+
}
11+
}
12+
return profit;
13+
}

0 commit comments

Comments
 (0)