728x90
https://leetcode.com/problems/count-number-of-pairs-with-absolute-difference-k
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
'IT > 코딩테스트' 카테고리의 다른 글
[Leetcode] 1684. Count the Number of Consistent Strings (0) | 2024.02.23 |
---|---|
[Leetcode] 1832. Check if the Sentence Is Pangram (0) | 2024.02.22 |
[Leetcode] 2367. Number of Arithmetic Triplets (0) | 2024.02.22 |
[Leetcode] 2325. Decode the Message (0) | 2024.02.21 |
[Leetcode] 1630. Arithmetic Subarrays (0) | 2024.02.20 |