License Key Formatting LeetCode solution in Python

1
# Runtime: 81 ms (Top 55.38%) | Memory: 14.3 MB (Top 86.51%)
2
class Solution:
3
def licenseKeyFormatting(self, s: str, k: int) -> str:
4
new_str = s.replace("-", "")
5
res = ""
6
j = len(new_str) - 1
7
i = 0
8
while j >= 0:
9
res += new_str[j].upper()
10
i += 1
11
if i == k and j != 0:
12
res += "-"
13
i = 0
14
j -= 1
15
return res[::-1]

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0