My solution - Python 5 line


  • 0
    M
    def licenseKeyFormatting(self, S, K):
            """
            :type S: str
            :type K: int
            :rtype: str
            """
            S = ''.join(S.split('-'))
            res = [S[:len(S) % K].upper()] if len(S) % K != 0 else []
            for i in range(1, len(S) / K + 1):
                res.append(S[len(S) % K + (i - 1) * K : len(S) % K + i * K].upper())
            return '-'.join(res)
    

Log in to reply
 

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