Python 3 lines


  • 0
    L

    Not much to explain :)

    class Solution(object):
        def licenseKeyFormatting(self, S, K):
            """
            :type S: str
            :type K: int
            :rtype: str
            """
            c = S.upper().replace('-', '')
            h = 1 + (len(c)-1) % K
            return '-'.join(c[max(i-K,0):i] for i in xrange(h, len(c)+1, K))
    

Log in to reply
 

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