LeetCode solutions

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

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 0ms, memory 12.3MB, accepted 2025-12-24.

python
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

Source