2021 KAKAO BLIND RECRUITMENT - 신규 아이디 추천 (Level 1)

 

https://programmers.co.kr/learn/courses/30/lessons/72410


Code

1
2
3
4
5
6
7
8
9
10
11
12
import re

def solution(new_id):
    st = new_id
    st = st.lower()
    st = re.sub('[^a-z0-9\-_.]', '', st)
    st = re.sub('\.+', '.', st)
    st = re.sub('^[.]|[.]$', '', st)
    st = 'a' if len(st) == 0 else st[:15]
    st = re.sub('^[.]|[.]$', '', st)
    st = st if len(st) > 2 else st + "".join([st[-1] for i in range(3-len(st))])
    return st

Complexity

$O(n)$

  • $n$: |new_id|