Untitled

 avatar
unknown
plain_text
a month ago
439 B
4
Indexable
class Solution {
public:
    bool canConstruct(string s, int k) {
        if(s.size()<k)return false;
        vector < int > freq(27, 0);

        for(int i=0;i<s.size();i++) {
            freq[s[i]-'a']++;
        }

        int oddCount = 0;

        for(int i=0;i<26;i++) {
            if(freq[i] & 1) {
                oddCount++;
            }
        }

        if(oddCount<=k)return true;
        return false;
    }
};

//creee
//7
Leave a Comment