标签:mat att pytho form for turn ret format pre
注意python的字符和数字转化函数是chr和ord
class Solution:
def licenseKeyFormatting(self, S: str, K: int) -> str:
lst = []
for c in S:
if c == ‘-‘:
continue
if c >= ‘a‘ and c <= ‘z‘:
c = chr(ord(c) - ord(‘a‘) + ord(‘A‘))
lst.append(c)
ret = ‘‘
for i in range(len(lst)):
ret += lst[i]
rem = len(lst) % K - 1
if rem < 0:
rem += K
if i != len(lst) - 1 and i % K == rem:
ret += ‘-‘
return ret
[leetcode]License Key Formatting
标签:mat att pytho form for turn ret format pre
原文地址:https://www.cnblogs.com/lautsie/p/12244785.html