Python clean solution


  • 0
    class Solution(object):
        def licenseKeyFormatting(self, S, K):
            letters = S.replace('-', '').upper()
            res = ''
            
            i = len(letters)
            while i-K >= 0:
                res = '-' + letters[i-K:i] + res
                i -= K
            res = letters[:i] + res
            
            return res.lstrip('-')
            
                
    

Log in to reply
 

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