https://school.programmers.co.kr/learn/courses/30/lessons/42576?language=python3
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
아이디어
Counter 라이브러리를 사용해서 해결했다.
처음에는 그냥 for loop 돌면서 구현했는데 효율성 테스트에서 막혔다.
전체 코드
from collections import Counter
def solution(participant, completion):
count = Counter(completion)
for p in participant:
if count[p] <= 0:
return p
count[p] -= 1
다른 사람의 코드
import collections
def solution(participant, completion):
answer = collections.Counter(participant) - collections.Counter(completion)
return list(answer.keys())[0]
Counter 끼리 뺄셈이 가능하다.. !!
'Coding Test > Python' 카테고리의 다른 글
[프로그래머스] 전화번호 목록(level2, python) (0) | 2024.01.10 |
---|---|
[프로그래머스] 폰켓몬(level1, python) (0) | 2024.01.10 |
[LeetCode] 54. Spiral Matrix (medium, python) (0) | 2024.01.09 |
[백준] 17779번: 게리맨더링 2 (골드3, 파이썬) (1) | 2024.01.08 |
[백준] 17140번: 이차원 배열과 연산 (골드4, 파이썬) (0) | 2024.01.06 |