Skip to content

Commit 46482ae

Browse files
committed
Solution as on 29-03-2022 10:00 pm
1 parent 433bef9 commit 46482ae

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

0409. Longest Palindrome.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// 409.✅ Longest Palindrome
2+
3+
class Solution
4+
{
5+
public:
6+
int longestPalindrome(string s)
7+
{
8+
map<char, int> m;
9+
bool odd = 0;
10+
for (auto i : s)
11+
++m[i];
12+
13+
int ind = 0;
14+
15+
for (auto i : m)
16+
{
17+
if (i.second % 2 == 0)
18+
ind += i.second;
19+
else
20+
{
21+
ind += i.second - 1;
22+
odd = true;
23+
}
24+
}
25+
if (odd)
26+
ind += 1;
27+
return ind;
28+
}
29+
};

0 commit comments

Comments
 (0)