imajinyun /
leetcode-php
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace leetcode; |
||
| 6 | |||
| 7 | class ArrayPartitionI |
||
| 8 | { |
||
| 9 | public static function arrayPairSum(array $nums): int |
||
| 10 | { |
||
| 11 | $ans = 0; |
||
|
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||
| 12 | if (empty($nums)) { |
||
| 13 | return 0; |
||
| 14 | } |
||
| 15 | sort($nums); |
||
| 16 | [$ans, $n] = [0, count($nums)]; |
||
| 17 | for ($i = 0; $i < $n; $i += 2) { |
||
| 18 | $ans += $nums[$i]; |
||
| 19 | } |
||
| 20 | |||
| 21 | return $ans; |
||
| 22 | } |
||
| 23 | } |
||
| 24 |