- Leetcode 482: License key formatting
- Level: Easy
- Link
My Approach
A simple string slicing problem
class Solution:
def licenseKeyFormatting(self, s: str, k: int) -> str:
s = s.replace('-', '').upper()
L = len(s)
if L == 1:
return s
ans = ""
ans += (s[0: L % k])
for i in range(L % k, L, k):
if len(ans) > 0:
ans += '-'
ans += s[i: i + k]
return (ans)
'개발공부 > algorithm' 카테고리의 다른 글
[Leetcode][python] 107: Binary Tree Level order Traversal II (0) | 2021.05.15 |
---|---|
[프로그래머스][python] 프린터 - Stack/queue (0) | 2021.05.08 |
[Leetcode][python] 120: triangle - DP (0) | 2021.04.29 |
[Leetcode][python] 973: K closest point to the origin (0) | 2021.04.28 |
[Leetcode][python] 929: Unique email addresses (0) | 2021.04.28 |