力扣:面试题 01.04. 回文排列

力扣:面试题 01.04. 回文排列_第1张图片

1、哈希表做法

class Solution {
public:
    bool canPermutePalindrome(string s) {
        int cnt=0;
        int hash[256]={0};
        for(int i=0;s[i];++i) ++hash[s[i]];
        for(int i=0;i<256;++i) if(hash[i]&1) ++cnt;
        if(cnt>1) return false;
        else return true;
    }
};

 

你可能感兴趣的:(力扣个人刷题题解,leetcode,算法,链表,c++)