728x90
분석
- 2 ≤ weights의 길이 ≤ 100,000이므로 조합으로 풀면 시간초과
풀이
from collections import Counter
def solution(weights):
answer = 0
counter = Counter(weights)
for c in counter:
answer += counter[c]*(counter[c]-1)//2
answer += counter[c]*counter[c*3/2]
answer += counter[c]*counter[c*2]
answer += counter[c]*counter[c*4/3]
return answer
728x90