|
@@ -0,0 +1,36 @@
|
|
|
|
|
+# 2006. Count Number of Pairs With Absolute Difference K
|
|
|
|
|
+
|
|
|
|
|
+import sys
|
|
|
|
|
+from typing import List
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+class Solution:
|
|
|
|
|
+ def countKDifference(self, nums: List[int], k: int) -> int:
|
|
|
|
|
+ return sum(
|
|
|
|
|
+ len(
|
|
|
|
|
+ [
|
|
|
|
|
+ 1
|
|
|
|
|
+ for j in range(len(nums))
|
|
|
|
|
+ if i < j and abs(nums[i] - nums[j]) == k
|
|
|
|
|
+ ]
|
|
|
|
|
+ )
|
|
|
|
|
+ for i in range(len(nums))
|
|
|
|
|
+ )
|
|
|
|
|
+ pass
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def main() -> int:
|
|
|
|
|
+ def r(ns: List[int], k: int) -> None:
|
|
|
|
|
+ print(
|
|
|
|
|
+ f"Solution().countKDifference({ns}, {k}) = {Solution().countKDifference(ns, k)}"
|
|
|
|
|
+ )
|
|
|
|
|
+ pass
|
|
|
|
|
+
|
|
|
|
|
+ r([1, 2, 2, 1], 1)
|
|
|
|
|
+ r([1, 3], 3)
|
|
|
|
|
+ r([3, 2, 1, 5, 4], 2)
|
|
|
|
|
+ return 0
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+if __name__ == "__main__":
|
|
|
|
|
+ sys.exit(main())
|