Skip to content

Latest commit

 

History

History
19 lines (17 loc) · 460 Bytes

2367.md

File metadata and controls

19 lines (17 loc) · 460 Bytes

2367. Number of Arithmetic Triplets

Solution 1 (time O(n), space O(n))

class Solution(object):
    def arithmeticTriplets(self, nums, diff):
        """
        :type nums: List[int]
        :type diff: int
        :rtype: int
        """
        s = set(nums)
        ans = 0
        for i in range(len(nums)):
            if nums[i] + diff in s and nums[i] + 2 * diff in s:
                ans += 1
        return ans