본문 바로가기

IT/코딩테스트

[Leetcode] 2367. Number of Arithmetic Triplets

728x90

https://leetcode.com/problems/number-of-arithmetic-triplets

 

LeetCode - The World's Leading Online Programming Learning Platform

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

class Solution:
    def arithmeticTriplets(self, nums: List[int], diff: int) -> int:
        count = 0

        for n in range(2, len(nums)):
            i = nums[n] - diff
            j = nums[n] - (2 * diff)
            
            if i in nums and j in nums:
                count += 1

        return count
728x90