题目链接:1995. 统计特殊四元组
暴力搜索。题目的数据范围很小,暴力搜就足够。
from itertools import combinations
from typing import List
class Solution:
def countQuadruplets(self, nums: List[int]) -> int:
return sum(a + b + c == d and i < j < k < l for (i, a), (j, b), (k, c), (l, d) in combinations(enumerate(nums), 4))