1995. Count Special Quadruplets

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1995

class Solution:
    def countQuadruplets(self, nums: List[int]) -> int:
        res, n = 0, len(nums)
        counter = Counter()
        for b in range(n - 3, 0, -1):
            c = b + 1
            for d in range(c + 1, n):
                counter[nums[d] - nums[c]] += 1
            for a in range(b):
                res += counter[nums[a] + nums[b]]
        return res