package
0.0.0-20241220224003-b7cf03a90b2b
Repository: https://github.com/szhou12/leetcode-go.git
Documentation: pkg.go.dev
# README
532. K-diff Pairs in an Array
Solution idea
Two Pointers - 一个数组 + 双指针同向而行
Key 1: Sort - 把input数组首先增序排列
Key 2: 为了避免重复,保证left
指针跳过重复的元素。
Key 3: 另外注意的一个细节就是,每确定一个左指针left
,都要重新定位右指针right=left+1
Time complexity = $O(n\log n) + O(n) = O(n\log n)$