Leetcode 482 Solution
This article provides solution to leetcode question 482 (license-key-formatting)
Access this page by simply typing in "lcs 482" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/license-key-formatting
Solution
class Solution {
public:
string licenseKeyFormatting(string S, int K) {
string t;
int cnt = 0;
for (int i = S.size() - 1; i >= 0; i--)
{
if (S[i] == '-')
continue;
if (cnt != 0 && cnt % K == 0)
t += "-";
t += toupper(S[i]);
cnt++;
}
reverse(t.begin(), t.end());
return t;
}
};