Another Python Solution


  • 0
    class Solution(object):
        def licenseKeyFormatting(self, S, K):
            res,s = [],S.replace('-','').upper()
            for i,c in enumerate(reversed(s),start=1):
                res += c,
                res += ['-'] if i%K==0 and i < len(s) else []
            return "".join(reversed(res))

Log in to reply
 

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