Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 구현
- nand
- Codetree
- 자율주행자동차
- 미친 아두이노
- 큐빙
- ML
- logic gate
- NOR
- 삼성
- 백준
- XOR
- Perceptron
- 코딩테스트
- python
- 프로그래머스
- Coding Test
- BFS
- BOJ
- 8972
- or
- dfs
- 파이썬
- 시뮬레이션
- 골드3
- 단어 변환
- and
- dl
- 5373
- Simulation
Archives
- Today
- Total
thkyang324
[프로그래머스] 불량 사용자 (Python 파이썬) 본문
불량 사용자
완전탐색, 순열
https://school.programmers.co.kr/learn/courses/30/lessons/64064
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
1<=len(banned_id)<=len(user_id)<=8 으로 매우 적은 경우의 수만이 존재한다. banned_id의 길이만큼 user_id에서 뽑아 매칭시켜보고, 매칭이 되는 경우를 세면 된다.
동일한 id의 user_id가 여러개 들어올 수 있다. 이 경우 제제 아이디 목록이 같아질 수 있으므로, Counter 모듈을 활용해 중복을 제거해준다.
제출 코드는 다음과 같다.
from itertools import permutations
from collections import Counter
def is_match(uid, bid):
""" 아이디가 banned_id에 매칭되는지 여부를 리턴 """
if len(uid) != len(bid):
return False
for u, b in zip(uid, bid):
if b=="*" or u==b:
continue
else:
return False
return True
def is_available_case(user_id, banned_id):
""" user_id리스트와 banned_id 리스트 (동일한 길이) 가 매칭되는지 여부를 리턴 """
for uid, bid in zip(user_id, banned_id):
if not is_match(uid, bid):
return False
return True
def solution(user_id, banned_id):
answer = []
# 순열을 통해 user_id에서 banned_id의 길이만큼 샘플링한 리스트에 대하여
for u_ids in permutations(user_id, len(banned_id)):
# 두 리스트가 매칭되는 경우
if is_available_case(u_ids, banned_id):
cnt = Counter(u_ids)
# 중복되지 않는다면 answer에 추가한다.
if cnt not in answer:
answer.append(cnt)
return len(answer)
'코딩테스트' 카테고리의 다른 글
[백준 BOJ 1285] 동전 뒤집기 (Python 파이썬) (0) | 2023.05.20 |
---|---|
[백준 BOJ 14499] 주사위 굴리기 (Python 파이썬) (0) | 2023.04.15 |
[프로그래머스] 괄호 변환 (Python 파이썬) (0) | 2023.04.15 |
[프로그래머스] 두 원 사이의 정수 쌍 (Python 파이썬) (0) | 2023.04.15 |
[프로그래머스] 요격 시스템 (Python 파이썬) (0) | 2023.04.15 |
Comments