<?php
class Solution {
/**
* @param String $s
* @return Integer
*/
function longestPalindrome($s) {
$map = [];
$len = strlen($s);
$count = 0;
for ($i = 0; $i < $len; $i++) {
$map[$s[$i]] = isset($map[$s[$i]]) ? ++$map[$s[$i]] : 1;
if ($map[$s[$i]] == 2) {
$count += $map[$s[$i]];
$map[$s[$i]] = 0;
}
}
if ($count < $len) {
$count++;
}
return $count;
}
}
$solution = new Solution();
var_dump($solution->longestPalindrome('abccccdd'));
力扣第409题
最新推荐文章于 2024-11-04 14:35:43 发布