본문 바로가기

IT/코딩테스트

[Leetcode] 2006. Count Number of Pairs With Absolute Difference K

728x90

https://leetcode.com/problems/count-number-of-pairs-with-absolute-difference-k

 

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 countKDifference(self, nums: List[int], k: int) -> int:
        count = 0

        for i in range(0, len(nums)):
            for j in range(i + 1, len(nums)):
                if abs(nums[i] - nums[j]) == k:
                    count += 1
        
        return count
728x90