classSolution { public: intcountLargestGroup(int n){ unordered_map<int, int> seen; int largestSize = 0; for (int i = 1; i <= n; ++i) { int sumOfDigit = 0; int current = i; while (current > 0) { sumOfDigit += current % 10; current /= 10; } ++seen[sumOfDigit]; largestSize = max(largestSize, seen[sumOfDigit]); } int ans = 0; for (auto it = seen.begin(); it != seen.end(); ++it) { if (it->second == largestSize) ++ans; } return ans; } };
classSolution { public: boolcanConstruct(string s, int k){ if (s.size() < k) returnfalse; vector<int> count(26, 0); for (char c : s) { ++count[c - 'a']; } int single = 0; for (int i : count) { if (i % 2 == 1) ++single; } return single <= k; } };