License Key Formatting (Leetcode 482)

Problem Link: https://leetcode.com/problems/license-key-formatting/

class Solution:
    def licenseKeyFormatting(self, s: str, k: int) -> str:
        
        t=''
        for i in range(len(s)):
            if(s[i]!='-'):
                t=t+s[i]
        s=t
        t=''
        c=0
        for i in range(len(s)-1,-1,-1):
            if(s[i].islower()):
                t=chr(ord(s[i])-32)+t
            else:
                t=s[i]+t
            c+=1
            if(c%k==0):
                if(i!=0):
                    t='-'+t
        return t

Last updated