首页 > 其他 > 详细

力扣第409题 最长回文串

时间:2020-03-23 00:46:11      阅读:65      评论:0      收藏:0      [点我收藏+]

力扣第409题 最长回文串

技术分享图片

技术分享图片

class Solution {
    public:
    int longestPalindrome(string s) {
        map<char, int> m_Map;
        for (int i = 0; i < s.size(); i++)
        {
            ++m_Map[s[i]];
        }
        bool state = false;
        int res = 0;
        for (map<char, int>::iterator itor = m_Map.begin(); itor != m_Map.end(); itor++)
        {
            if ((*itor).second & 1)
            {
                state = true;
                res += (*itor).second - 1;
            }
            else
            {
                res += (*itor).second;
            }
        }
        if (state)
            res++;
        return res;
    }
};

力扣第409题 最长回文串

原文:https://www.cnblogs.com/woodjay/p/12528070.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!