4-line C++ solution, beats 85% of other submissions

  • 0

    My understanding is that this problem tests knowledge of the Standard C++ Library:

        string licenseKeyFormatting(string s, int k) {
            transform(s.begin(), s.end(), s.begin(), ::toupper);
            s.erase(remove(s.begin(), s.end(), '-'), s.end());
            for(int i = s.size() - k; i > 0; i -= k)
                s.insert(i, 1, '-');
            return s;

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.