# number = [-3, -2, -1, 0, 1, 2, 3] -> 5
# 학생들의 정수 번호 쌍 (-3, 0, 3), (-2, 0, 2), (-1, 0, 1), (-2, -1, 3), (-3, 1, 2) 이 삼총사가 될 수 있음
# => 5
## 의사코드 ##
# 학생들의 정수 번호 쌍을 구함
# -> combinations(number, 3)
# 정수 번호 쌍의 합이 0인 경우 answer += 1
통과한 코드
from itertools import combinations
def solution(number):
answer = 0
combi = list(combinations(number, 3))
for a, b, c in combi:
if a+b+c == 0:
answer += 1
return answer
다른 풀이
from itertools import combinations
def solution(number):
return len([sum(nums) for nums in combinations(number, 3) if sum(nums) == 0])