class Solution {
public:
int longestPalindrome(string s) {
unordered_map<char,int> cnt;
int rst = 0;
bool flag = false;
for(char c : s)
++cnt[c];
for(auto p : cnt){
if(p.second%2 == 0)
rst += p.second;
else{
rst += p.second-1;
flag = true;
}
}
return flag ? rst+1 : rst;
}
};
Leetcode 409. 最长回文串
最新推荐文章于 2024-07-19 19:25:43 发布