from collections import Counter
def solution(weights):
answer = 0
weights.sort()
counter = Counter(weights)
for (w, c) in counter.items():
answer += c * (c-1) // 2 # 1:1
answer += c * counter[w*2] # 2:1
answer += c * counter[w*3/2] # 3:2
answer += c * counter[w*4/3] # 4:3
return answer
# https://school.programmers.co.kr/learn/courses/30/lessons/152996'Data Engineering > Python' 카테고리의 다른 글
| [코테] 프로그래머스 - 합승 택시 요금 Python 코드 (0) | 2025.10.16 |
|---|---|
| [코테] 프로그래머스 - 베스트앨범 Python 코드 (0) | 2025.10.15 |
| [코테] 프로그래머스 - 삼각 달팽이 Python 코드 (0) | 2025.10.15 |
| [코테] 프로그래머스 - 가장 큰 수 Python 코드 (0) | 2025.09.18 |
| [코테] 프로그래머스 - 더 맵게 Python 코드 (0) | 2025.09.18 |