title: "[프로그래머스] 시소 짝꿍 Python 파이썬 해설 (Level 2) - 이도훈"
cleanUrl: "programmers/152996"
description: "프로그래머스 Level 2 문제 [시소 짝꿍]의 풀이를 정리합니다."
from collections import Counter
def solution(weights):
answer = 0
# 같은 weight가 있는 경우는 따로 처리해줍니다.
counter = Counter(weights)
for w, cnt in counter.items():
answer += cnt * (cnt - 1) // 2
wset = set(weights)
for w in weights:
# 4/3배
if w % 3 == 0:
target_weight = w * 4 // 3
answer += counter[target_weight]
# 3/2배
if w % 2 == 0:
target_weight = w * 3 // 2
answer += counter[target_weight]
# 2배
target_weight = w * 2
answer += counter[target_weight]
return answer
프로그래머스 코딩테스트 연습 https://school.programmers.co.kr/learn/challenges