2442. Number of Arithmetic Triplets
My accepted Python solution to LeetCode problem 2442, Number of Arithmetic Triplets, running in 0ms.
- Difficulty: Easy
- Python
- Runtime 0ms
- Memory 12.3MB
- 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 0ms, memory 12.3MB, accepted 2025-12-24.
class Solution(object):
def arithmeticTriplets(self, nums, diff):
num_set = set(nums)
count = 0
for num in nums:
if num + diff in num_set and num + 2 * diff in num_set:
count += 1
return count