File tree Expand file tree Collapse file tree 3 files changed +61
-0
lines changed
solution/1400-1499/1464.Maximum Product of Two Elements in an Array Expand file tree Collapse file tree 3 files changed +61
-0
lines changed Original file line number Diff line number Diff line change @@ -300,6 +300,28 @@ impl Solution {
300
300
}
301
301
```
302
302
303
+ ### ** PHP**
304
+
305
+ ``` php
306
+ class Solution {
307
+ /**
308
+ * @param Integer[] $nums
309
+ * @return Integer
310
+ */
311
+ function maxProduct($nums) {
312
+ $max = 0;
313
+ $submax = 0;
314
+ for ($i = 0; $i < count($nums); $i++) {
315
+ if ($nums[$i] > $max) {
316
+ $submax = $max;
317
+ $max = $nums[$i];
318
+ } else if ($nums[$i] > $submax) $submax = $nums[$i];
319
+ }
320
+ return ($max - 1) * ($submax - 1);
321
+ }
322
+ }
323
+ ```
324
+
303
325
### ** ...**
304
326
305
327
```
Original file line number Diff line number Diff line change @@ -275,6 +275,28 @@ impl Solution {
275
275
}
276
276
```
277
277
278
+ ### ** PHP**
279
+
280
+ ``` php
281
+ class Solution {
282
+ /**
283
+ * @param Integer[] $nums
284
+ * @return Integer
285
+ */
286
+ function maxProduct($nums) {
287
+ $max = 0;
288
+ $submax = 0;
289
+ for ($i = 0; $i < count($nums); $i++) {
290
+ if ($nums[$i] > $max) {
291
+ $submax = $max;
292
+ $max = $nums[$i];
293
+ } else if ($nums[$i] > $submax) $submax = $nums[$i];
294
+ }
295
+ return ($max - 1) * ($submax - 1);
296
+ }
297
+ }
298
+ ```
299
+
278
300
### ** ...**
279
301
280
302
```
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ /**
3
+ * @param Integer[] $nums
4
+ * @return Integer
5
+ */
6
+ function maxProduct ($nums ) {
7
+ $max = 0 ;
8
+ $submax = 0 ;
9
+ for ($i = 0 ; $i < count ($nums ); $i ++ ) {
10
+ if ($nums [$i ] > $max ) {
11
+ $submax = $max ;
12
+ $max = $nums [$i ];
13
+ } else if ($nums [$i ] > $submax ) $submax = $nums [$i ];
14
+ }
15
+ return ($max - 1 ) * ($submax - 1 );
16
+ }
17
+ }
You can’t perform that action at this time.
0 commit comments