LeetCode 482 License Key Formatting

LeetCode 482 License Key Formatting Problem

Download Code
class Solution(object):
    def licenseKeyFormatting(self, S, K):
        """
        :type S: str
        :type K: int
        :rtype: str
        """
        # https://leetcode.com/problems/license-key-formatting/discuss/96497/Python-solution
        S = S.upper().replace('-', '')
        ls = len(S)
        if ls % K == 0:
            pos = K
        else:
            pos = ls % K
        res = S[:pos]
        while pos < ls:
            res += '-' + S[pos:pos + K]
            pos += K
        return res
Download License Key Formatting.py

List of all License Key Formatting problems

Leetcode 482 License Key Formatting problem solution in python3 with explanation. This is the best place to expand your knowledge and get prepared for your next interview.

Feedback is the most important part of any website.

If you have any query, suggestion or feedback, Please feel free to contact us.