HTMLify

LeetCode - License Key Formatting - Python
Views: 11 | Author: abh
class Solution:
    def licenseKeyFormatting(self, s: str, k: int) -> str:
        while "-" in s:
            s = s.replace("-", "")
        s = s.upper()
        fk = ""
        while True:
            if len(s) <= k:
                fk = s + fk
                break
            fk = "-" + s[-k:] + fk
            s = s[:-k]
        return fk

Comments