-
-
Notifications
You must be signed in to change notification settings - Fork 298
/
Copy path482.py
31 lines (30 loc) · 1.07 KB
/
482.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
__________________________________________________________________________________________________
sample 28 ms submission
class Solution:
def licenseKeyFormatting(self, S: str, K: int) -> str:
S=''.join(S.split('-')).upper()
result=[]
s=len(S)%K
n=len(S)//K
if s>0:
result.append(S[:s])
for i in range(1,n+1):
result.append(S[s+(i-1)*K:s+i*K])
return '-'.join(result)
__________________________________________________________________________________________________
sample 13392 kb submission
class Solution:
def licenseKeyFormatting(self, S: str, K: int) -> str:
ret = ''
count = 0
for i in range(len(S) - 1, -1, -1):
char = S[i].upper()
if char == '-':
continue
if count > 0 and count % K == 0:
ret = '-' + ret
count = 0
ret = char + ret
count += 1
return ret
__________________________________________________________________________________________________