File tree 3 files changed +58
-0
lines changed
solution/0100-0199/0121.Best Time to Buy and Sell Stock
3 files changed +58
-0
lines changed Original file line number Diff line number Diff line change @@ -189,6 +189,27 @@ impl Solution {
189
189
}
190
190
```
191
191
192
+ ### ** PHP**
193
+
194
+ ``` php
195
+ class Solution {
196
+ /**
197
+ * @param Integer[] $prices
198
+ * @return Integer
199
+ */
200
+ function maxProfit($prices) {
201
+ $win = 0;
202
+ $minPrice = $prices[0];
203
+ $len = count($prices);
204
+ for ($i = 1; $i < $len; $i++) {
205
+ $minPrice = min($minPrice, $prices[$i]);
206
+ $win = max($win, $prices[$i] - $minPrice);
207
+ }
208
+ return $win;
209
+ }
210
+ }
211
+ ```
212
+
192
213
### ** ...**
193
214
194
215
```
Original file line number Diff line number Diff line change @@ -173,6 +173,27 @@ impl Solution {
173
173
}
174
174
```
175
175
176
+ ### ** PHP**
177
+
178
+ ``` php
179
+ class Solution {
180
+ /**
181
+ * @param Integer[] $prices
182
+ * @return Integer
183
+ */
184
+ function maxProfit($prices) {
185
+ $win = 0;
186
+ $minPrice = $prices[0];
187
+ $len = count($prices);
188
+ for ($i = 1; $i < $len; $i++) {
189
+ $minPrice = min($minPrice, $prices[$i]);
190
+ $win = max($win, $prices[$i] - $minPrice);
191
+ }
192
+ return $win;
193
+ }
194
+ }
195
+ ```
196
+
176
197
### ** ...**
177
198
178
199
```
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ /**
3
+ * @param Integer[] $prices
4
+ * @return Integer
5
+ */
6
+ function maxProfit ($prices ) {
7
+ $win = 0 ;
8
+ $minPrice = $prices [0 ];
9
+ $len = count ($prices );
10
+ for ($i = 1 ; $i < $len ; $i ++ ) {
11
+ $minPrice = min ($minPrice , $prices [$i ]);
12
+ $win = max ($win , $prices [$i ] - $minPrice );
13
+ }
14
+ return $win ;
15
+ }
16
+ }
You can’t perform that action at this time.
0 commit comments