Python


  • 0
    B
    class Solution(object):
        def licenseKeyFormatting(self, S, K):
            """
            :type S: str
            :type K: int
            :rtype: str
            """
            if len(S) < 1: return ""
            l = []
            for v in S:
                    if v == '-':
                            continue
                    l.append(v.upper())
            idx = len(l)
            while(idx > K): 
                    l.insert(idx-K, '-')
                    idx = idx-K
    
            return "".join(l)
    

Log in to reply
 

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