leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1400.cpp (589B)


0 class Solution { 1 public: 2 bool canConstruct(const string &s, int k) { 3 if (s.size() < k) return false; 4 5 int count[27] = {0}; 6 for (const char c : s) 7 count[c & 0x1F]++; 8 9 int singles = 0; 10 for (int i = 1; i <= 26; i++) 11 singles += count[i] & 1; 12 return singles <= k; 13 } 14 }; 15 16 class Solution { 17 public: 18 bool canConstruct(const string &s, int k) { 19 if (s.size() < k) return false; 20 21 bitset<27> bs; 22 for (const char c : s) 23 bs.flip(c & 0x1F); 24 return bs.count() <= k; 25 } 26 };