License Key Formatting
就是普通的模拟题目过程字符串处理,没有什么特殊的,注意使用Python库的函数就好了
class Solution(object):
def licenseKeyFormatting(self, S, K):
"""
:type S: str
:type K: int
:rtype: str
"""
strings = reduce(operator.add, [list(x) for x in S.split('-')])
n = len(strings)
result = ''
while n >= K:
tmp = ''.join(strings[n - K : n])
result = '-' + tmp + result
n -= K
if n:
return (''.join(strings[:n]) + result).upper()
return result[1:].upper()