当前位置:网站首页>Daily question 2006 Number of pairs whose absolute value of difference is k
Daily question 2006 Number of pairs whose absolute value of difference is k
2022-07-05 05:42:00 【A big pigeon】
topic : Given array nums And integer k, In the array Satisfy |nums[i]-nums[j]| = k(i<j) Number to number .
Explain :1. Direct double cycle
class Solution:
def countKDifference(self, nums: List[int], k: int) -> int:
cnt = 0
for i in range(len(nums)):
for j in range(i+1,len(nums)):
if abs(nums[j]-nums[i]) == k:
cnt += 1
return cnt2. Hashtable
class Solution:
def countKDifference(self, nums: List[int], k: int) -> int:
cnt, ans = Counter(nums), 0
for key in cnt:
if (key + k) in cnt:
ans += cnt[key] * cnt[key + k]
return ans边栏推荐
- Using HashMap to realize simple cache
- In this indifferent world, light crying
- Scope of inline symbol
- [practical skills] technical management of managers with non-technical background
- Common optimization methods
- Codeforces Round #732 (Div. 2) D. AquaMoon and Chess
- Demonstration of using Solon auth authentication framework (simpler authentication framework)
- Gbase database helps the development of digital finance in the Bay Area
- 网络工程师考核的一些常见的问题:WLAN、BGP、交换机
- [jailhouse article] look mum, no VM exits
猜你喜欢

Little known skills of Task Manager

SAP method of modifying system table data

API related to TCP connection

剑指 Offer 04. 二维数组中的查找

个人开发的渗透测试工具Satania v1.2更新

sync.Mutex源码解读
![[jailhouse article] performance measurements for hypervisors on embedded ARM processors](/img/c0/4843f887f77b80e3b2329e12d28987.png)
[jailhouse article] performance measurements for hypervisors on embedded ARM processors

Scope of inline symbol

Educational Codeforces Round 116 (Rated for Div. 2) E. Arena

读者写者模型
随机推荐
[jailhouse article] performance measurements for hypervisors on embedded ARM processors
“磐云杯”中职网络安全技能大赛A模块新题
Acwing 4301. Truncated sequence
High precision subtraction
Implement an iterative stack
Introduction to tools in TF-A
Solution to game 10 of the personal field
Introduction et expérience de wazuh open source host Security Solution
【实战技能】非技术背景经理的技术管理
Use of room database
Wazuh开源主机安全解决方案的简介与使用体验
剑指 Offer 58 - II. 左旋转字符串
个人开发的渗透测试工具Satania v1.2更新
API related to TCP connection
Corridor and bridge distribution (csp-s-2021-t1) popular problem solution
Reflection summary of Haut OJ freshmen on Wednesday
游戏商城毕业设计
Codeforces Round #715 (Div. 2) D. Binary Literature
SAP method of modifying system table data
Sword finger offer 06 Print linked list from beginning to end