2122. Count Special Quadruplets
My accepted Python solution to LeetCode problem 2122, Count Special Quadruplets, running in 543ms.
- Difficulty: Easy
- Python
- Runtime 543ms
- Memory 17.1MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 543ms, memory 17.1MB, accepted 2025-12-29.
class Solution:
def countQuadruplets(self, nums: List[int]) -> int:
n = len(nums)
count = 0
for a in range(n):
for b in range(a + 1, n):
for c in range(b + 1, n):
for d in range(c + 1, n):
if nums[a] + nums[b] + nums[c] == nums[d]:
count += 1
return count