欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

[leetcode]01.04. 回文排列

程序员文章站 2024-03-04 09:58:41
...

[leetcode]01.04. 回文排列
额额,例子是错的。。。我为什么要点开。。。。。。。
[leetcode]01.04. 回文排列
[leetcode]01.04. 回文排列

class Solution {
public:
    bool canPermutePalindrome(string s) {
        unordered_map<char,int>hash;
        for(int i = 0; i < s.size(); i++)
        {
            hash[s[i]]++;
        }
        int cnt = 0; //字母出现个数只能有一次是奇数
        unordered_map<char,int>::iterator it;
        for(it = hash.begin(); it != hash.end(); it++)
        {
            if(it->second % 2 == 1)
            {
                cnt++;
                if(cnt == 2)
                {
                    return false;
                }
            }
        }
        return true;
    }
};

[leetcode]01.04. 回文排列

相关标签: leetcode