License Key Formatting LeetCode solution in Python
1# Runtime: 81 ms (Top 55.38%) | Memory: 14.3 MB (Top 86.51%)2class Solution:3def licenseKeyFormatting(self, s: str, k: int) -> str:4new_str = s.replace("-", "")5res = ""6j = len(new_str) - 17i = 08while j >= 0:9res += new_str[j].upper()10i += 111if i == k and j != 0:12res += "-"13i = 014j -= 115return res[::-1]