Skip to content

Commit 0313be0

Browse files
author
Partho Biswas
committed
leetcode 482. License Key Formatting
1 parent ae737c3 commit 0313be0

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution(object):
2+
def licenseKeyFormatting(self, S, K):
3+
"""
4+
:type S: str
5+
:type K: int
6+
:rtype: str
7+
"""
8+
S = ''.join(S.split('-')).upper()
9+
reminder = K if len(S) % K == 0 else len(S) % K
10+
currentIdx = reminder
11+
resultS = S[:currentIdx]
12+
while currentIdx < len(S):
13+
resultS += '-' + S[currentIdx: currentIdx + K]
14+
currentIdx += K
15+
return resultS
16+
17+
18+
19+
sol = Solution()
20+
input = "5F3Z-2e-9-w"
21+
output = sol.licenseKeyFormatting(input, 4)
22+
print('Output: ', output)

0 commit comments

Comments
 (0)