C++ || beginner Friendly  || Map
Method \nusing hash map\nTime Complexity-O(n)\n\n\nclass Solution {\npublic:\n    int longestPalindrome(string s) {\n        map<char,int>mp;\n        int ans=0
Method \nusing hash map\nTime Complexity-O(n)\n![image](https://assets.leetcode.com/users/images/edb97231-cfe2-4db0-aaa0-54258a516054_1692674930.7326834.png)\n```\nclass Solution {\npublic:\n    int longestPalindrome(string s) {\n        map<char,int>mp;\n        int ans=0;\n        for(int i=0;i<s.size();i++){\n            mp[s[i]]++;\n        }\n        int count=0;\n        for(auto i:mp){\n            if(i.second%2==1 && count==1){  // when we find one old then convert remaining old to even \n                ans=ans+i.second-1;\n            }\n            else if(i.second%2==1){  // when we find first old then\n                count++;\n                if(count==1){\n                ans=ans+i.second;   //add all element beacuse one element are at middle\n                }\n            }\n            else if(i.second%2==0){  //for even case add all element\n                ans=ans+i.second;\n            }\n            \n        }\n        return ans;\n    }\n};\n```\n![image](https://assets.leetcode.com/users/images/1d794c25-a72b-41c6-9394-ced745318f73_1692674944.5354667.webp)\n
['C']