동까의 코딩

99클럽 코테 스터디 TIL 본문

문제 풀이/99클럽

99클럽 코테 스터디 TIL

동까의 코딩 2025. 2. 12. 10:33
반응형

https://school.programmers.co.kr/learn/courses/30/lessons/64064

 

프로그래머스

SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

 

itertools의 permutations를 사용해서 모든 경우의 수를 만들어주면서 풀이하였습니다.

 

def solution(user_id, banned_id):
    answer=0
    import re
    from itertools import permutations
    answers = []
    for p in permutations(user_id, len(banned_id)):
        cnt = 0
        for i in range(len(p)):
            ban = banned_id[i].replace('*','.')
            if re.match(ban,p[i]) and len(ban)==len(p[i]):
                cnt+=1
        if cnt==len(banned_id):
            p = sorted(p)
            if p not in answers:
                answers.append(p)
                
    answer = len(answers)
    
    return answer
반응형

'문제 풀이 > 99클럽' 카테고리의 다른 글

99클럽 코테 스터디 TIL  (0) 2025.02.15
99클럽 코테 스터디 TIL  (0) 2025.02.13
99클럽 코테 스터디 TIL 11일차  (0) 2025.02.07
99클럽 코테 스터디 TIL 10일차  (0) 2025.02.05
99클럽 코테 스터디 TIL 9일차  (0) 2025.02.04