We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5518955 commit 4716598Copy full SHA for 4716598
532-k-diff-pairs-in-an-array.js
@@ -0,0 +1,28 @@
1
+/**
2
+ * @param {number[]} nums
3
+ * @param {number} k
4
+ * @return {number}
5
+ */
6
+const findPairs = function(nums, k) {
7
+ if(k < 0) return 0
8
+ let count = 0
9
+ const hash = {}
10
+ for(let el of nums) {
11
+ if (hash.hasOwnProperty(el)) {
12
+ if(k === 0 && hash[el] === 1) {
13
+ count++
14
+ }
15
+ hash[el] += 1
16
+ } else {
17
+ if (hash.hasOwnProperty(el - k)) {
18
19
20
+ if (hash.hasOwnProperty(el + k)) {
21
22
23
+ hash[el] = 1
24
25
26
+
27
+ return count
28
+};
0 commit comments