https://school.programmers.co.kr/learn/courses/30/lessons/152996
코드
from collections import Counter
def solution(weights):
answer = 0
times = (3/4, 2/3, 1/2)
count_dict = Counter(weights)
for key, value in count_dict.items():
if value > 1:
answer += value * (value - 1) / 2
# weights 안에 중복 없애기
weights = list(set(weights))
# 같은 무게가 아닐 경우
for i in weights:
for j in times:
if i * j in weights:
combination_num = count_dict[i * j] # 조합 갯수
answer += combination_num * count_dict[i]
return answer
참조
https://jibinary.tistory.com/48
[Python] [Level 2] 시소 짝꿍 (Counter 함수 활용하기)
프로그래머스 문제 시소 짝꿍 https://school.programmers.co.kr/learn/courses/30/lessons/152996 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록
jibinary.tistory.com
'코딩테스트 > programmers (python)' 카테고리의 다른 글
Programmers / 2단계 / 미로 탈출 / python (0) | 2024.05.14 |
---|---|
Programmers / 3단계 / 호텔 대실 / python (0) | 2024.05.13 |
Programmers / 3단계 / 마법의 엘리베이터 / python (0) | 2024.05.09 |
Programmers / 2단계 / 괄호 변환 / python / 2020 KAKAO BLIND RECRUITMENT (0) | 2024.05.08 |
Programmers / 3단계 / 스티커 모으기(2) / python (0) | 2024.05.07 |