mirror of
https://git.wolves.top/wolves/leetcode.git
synced 2025-11-04 17:26:32 +08:00
init
This commit is contained in:
20
greed/409.h
Normal file
20
greed/409.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
using namespace std;
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
int longestPalindrome(string s) {
|
||||
unordered_map<char, int> count;
|
||||
int ans = 0;
|
||||
for (char c : s)
|
||||
++count[c];
|
||||
for (auto p : count) {
|
||||
int v = p.second;
|
||||
ans += v / 2 * 2;
|
||||
if (v % 2 == 1 and ans % 2 == 0)
|
||||
++ans;
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user