Skip to content

Commit 48ebca3

Browse files
committed
Add js solution to readme for leetcode problem: no.121
1 parent 858ed91 commit 48ebca3

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

solution/0100-0199/0121.Best Time to Buy and Sell Stock/README.md

+18
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,24 @@ class Solution {
8383
}
8484
```
8585

86+
### **JavaScript**
87+
88+
```js
89+
const maxProfit1 = function (prices) {
90+
let min = prices[0];
91+
let profit = 0;
92+
for (let i = 0; i < prices.length; i++) {
93+
if (prices[i] < min) {
94+
min = prices[i];
95+
}
96+
if (profit < prices[i] - min) {
97+
profit = prices[i] - min;
98+
}
99+
}
100+
return profit;
101+
};
102+
```
103+
86104
### **...**
87105

88106
```

solution/0100-0199/0121.Best Time to Buy and Sell Stock/README_EN.md

+18
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,24 @@ class Solution {
7373
}
7474
```
7575

76+
### **JavaScript**
77+
78+
```js
79+
const maxProfit1 = function (prices) {
80+
let min = prices[0];
81+
let profit = 0;
82+
for (let i = 0; i < prices.length; i++) {
83+
if (prices[i] < min) {
84+
min = prices[i];
85+
}
86+
if (profit < prices[i] - min) {
87+
profit = prices[i] - min;
88+
}
89+
}
90+
return profit;
91+
};
92+
```
93+
7694
### **...**
7795

7896
```

0 commit comments

Comments
 (0)