C++


  • 0
    S
    class Solution {
    public:
        string licenseKeyFormatting(string S, int K) {
            string result;
            
            for (auto it = S.rbegin(); it < S.rend(); ++it) {
                if (*it == '-') {
                    continue;
                }
                if (result.length() % (K + 1) == K) {
                    result += '-';
                }
                result += toupper(*it);
            }
            reverse(result.begin(), result.end());
            
            return result;
        }
    };
    

Log in to reply
 

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