Description
Submission
class Solution { public: string licenseKeyFormatting(string s, int k) { string ret; int cnt = 0; for(int i = s.length() - 1; i >= 0; --i) { if(s[i] == '-') continue; if(cnt != 0 && cnt % k == 0) ret.push_back('-'); ret.push_back(toupper(s[i])); ++cnt; } reverse(ret.begin(), ret.end()); return ret; } };