leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0482.cpp (438B)
0 class Solution { 1 public: 2 string licenseKeyFormatting(const string &s, int k) const { 3 const int n = std::count(begin(s), end(s), '-'); 4 const int m = size(s) - n; 5 6 string res; 7 int goal = m % k ? m % k + 1 : k + 1; 8 for (const char c : s) { 9 if (c == '-') continue; 10 if (!--goal) res += '-', goal = k; 11 12 res += toupper(c); 13 } 14 15 return res; 16 } 17 };