Skip to content

Commit

Permalink
Time: 3 ms (87.21%), Space: 6.7 MB (15.27%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
Dipendra-Raghav committed Dec 7, 2022
1 parent 2f65dd0 commit bfddb95
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions 0409-longest-palindrome/0409-longest-palindrome.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Solution {
public:
int longestPalindrome(string s) {
unordered_map<char,int> mp;
for(int i=0;i<s.size();i++)
{
mp[s[i]]++;
}
bool flag=false;
int ans=0;
for(auto it=mp.begin();it!=mp.end();it++)
{
if(it->second%2==0)
ans+=it->second;
else
{
ans+=it->second-1;
flag=true;
}
}
ans=flag==true?ans+1:ans;
return ans;
}
};

0 comments on commit bfddb95

Please sign in to comment.