Skip to content

Commit 49806b6

Browse files
committed
Runtime: 11 ms (Top 50.6%) | Memory: 43.63 MB (Top 70.1%)
1 parent b071b73 commit 49806b6

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Runtime: 11 ms (Top 50.6%) | Memory: 43.63 MB (Top 70.1%)
2+
3+
// O(n) Time Solution
4+
5+
class Solution {
6+
public int findPairs(int[] nums, int k) {
7+
Map<Integer, Integer> map = new HashMap();
8+
for (int num : nums)
9+
map.put(num, map.getOrDefault(num, 0) + 1);
10+
11+
int result = 0;
12+
for (int i : map.keySet())
13+
if (k > 0 && map.containsKey(i + k) || k == 0 && map.get(i) > 1)
14+
result++;
15+
return result;
16+
}
17+
}

0 commit comments

Comments
 (0)