| Total Complexity | 11 |
| Total Lines | 36 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | class LongestPalindrome |
||
| 8 | { |
||
| 9 | public static function longestPalindrome(string $s): int |
||
| 10 | { |
||
| 11 | if (empty($s)) { |
||
| 12 | return 0; |
||
| 13 | } |
||
| 14 | [$ans, $map] = [0, []]; |
||
| 15 | for ($i = 0, $n = strlen($s); $i < $n; $i++) { |
||
| 16 | $map[$s[$i]] = ($map[$s[$i]] ?? 0) + 1; |
||
| 17 | if ($map[$s[$i]] === 2) { |
||
| 18 | $ans += 2; |
||
| 19 | unset($map[$s[$i]]); |
||
| 20 | } |
||
| 21 | } |
||
| 22 | |||
| 23 | return $map ? $ans + 1 : $ans; |
||
|
|
|||
| 24 | } |
||
| 25 | |||
| 26 | public static function longestPalindrome2(string $s): int |
||
| 43 | } |
||
| 44 | } |
||
| 45 |