Total Complexity | 9 |
Total Lines | 40 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
7 | class TwoSumLessThanK |
||
8 | { |
||
9 | public static function twoSumLessThanK(array $nums, int $k): int |
||
10 | { |
||
11 | $ans = -1; |
||
12 | if (empty($nums)) { |
||
13 | return $ans; |
||
14 | } |
||
15 | $n = count($nums); |
||
16 | for ($i = 0; $i < $n; $i++) { |
||
17 | for ($j = 1; $j < $n; $j++) { |
||
18 | $sum = $nums[$i] + $nums[$j]; |
||
19 | if ($sum < $k) { |
||
20 | $ans = max($ans, $sum); |
||
21 | } |
||
22 | } |
||
23 | } |
||
24 | |||
25 | return $ans; |
||
26 | } |
||
27 | |||
28 | public static function twoSumLessThanK2(array $nums, int $k): int |
||
47 | } |
||
48 | } |
||
49 |