Conditions | 7 |
Paths | 16 |
Total Lines | 22 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
32 | public static function largestUniqueNumber2(array $nums): int |
||
33 | { |
||
34 | if (empty($nums)) { |
||
35 | return -1; |
||
36 | } |
||
37 | $n = count($nums); |
||
|
|||
38 | [$map, $max, $min] = [[], -1, 1001]; |
||
39 | foreach ($nums as $num) { |
||
40 | $map[$num] = ($map[$num] ?? 0) + 1; |
||
41 | $max = $max > $num ? $max : $num; |
||
42 | $min = $min < $num ? $min : $num; |
||
43 | } |
||
44 | [$ans, $tmp] = [-1, $max]; |
||
45 | while ($tmp >= $min) { |
||
46 | if ($map[$tmp] === 1) { |
||
47 | $ans = $tmp; |
||
48 | break; |
||
49 | } |
||
50 | $tmp--; |
||
51 | } |
||
52 | |||
53 | return $ans; |
||
54 | } |
||
56 |