HR-Pairs
Last updated
Was this helpful?
Last updated
Was this helpful?
Given integers, count the number of pairs of integers whose difference is K.
解体思路: Set
边界条件: 数组有值。 1 直接解题, 先把数组排序,然后从前往后,找 v+k的值,如果数组值已近大于 v+k, 停止查询。从头继续下一个值查找。
2 使用 HashSet, 每值放入hashset, 同时比较 v+k 还是 v-k 在不在 set里,如果再就总数加