Skip to content

Commit d4bcdcc

Browse files
authored
feat: add php solution to lc problem: No.1464 (doocs#1019)
1 parent 0e66e0a commit d4bcdcc

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

solution/1400-1499/1464.Maximum Product of Two Elements in an Array/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,28 @@ impl Solution {
300300
}
301301
```
302302

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+
303325
### **...**
304326

305327
```

solution/1400-1499/1464.Maximum Product of Two Elements in an Array/README_EN.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,28 @@ impl Solution {
275275
}
276276
```
277277

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+
278300
### **...**
279301

280302
```
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
}

0 commit comments

Comments
 (0)