File tree 2 files changed +36
-0
lines changed
solution/0100-0199/0121.Best Time to Buy and Sell Stock
2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -83,6 +83,24 @@ class Solution {
83
83
}
84
84
```
85
85
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
+
86
104
### ** ...**
87
105
88
106
```
Original file line number Diff line number Diff line change @@ -73,6 +73,24 @@ class Solution {
73
73
}
74
74
```
75
75
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
+
76
94
### ** ...**
77
95
78
96
```
You can’t perform that action at this time.
0 commit comments