Skip to content

Commit e128740

Browse files
authored
Create 409. Longest Palindrome (#494)
2 parents 23f9915 + bc9e953 commit e128740

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

409. Longest Palindrome

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public:
3+
int longestPalindrome(string s) {
4+
int c = 0; // odd count
5+
unordered_map<char, int>m;
6+
for(auto ch : s) {
7+
m[ch]++;
8+
if (m[ch] & 1)
9+
c++;
10+
else
11+
c--;
12+
}
13+
if (c > 1)
14+
return s.length() - c + 1;
15+
return s.length();
16+
}
17+
};

0 commit comments

Comments
 (0)