|
3 | 3 | import java.util.HashMap;
|
4 | 4 | import java.util.Map;
|
5 | 5 |
|
6 |
| -/** |
7 |
| - * 532. K-diff Pairs in an Array |
8 |
| - * |
9 |
| - * Given an array of integers and an integer k, you need to find the number of unique k-diff pairs in the array. |
10 |
| - * Here a k-diff pair is defined as an integer pair (i, j), where i and j are both numbers in the array and their absolute difference is k. |
11 |
| -
|
12 |
| - Example 1: |
13 |
| - Input: [3, 1, 4, 1, 5], k = 2 |
14 |
| - Output: 2 |
15 |
| - Explanation: There are two 2-diff pairs in the array, (1, 3) and (3, 5). |
16 |
| - Although we have two 1s in the input, we should only return the number of unique pairs. |
17 |
| -
|
18 |
| - Example 2: |
19 |
| - Input:[1, 2, 3, 4, 5], k = 1 |
20 |
| - Output: 4 |
21 |
| - Explanation: There are four 1-diff pairs in the array, (1, 2), (2, 3), (3, 4) and (4, 5). |
22 |
| -
|
23 |
| - Example 3: |
24 |
| - Input: [1, 3, 1, 5, 4], k = 0 |
25 |
| - Output: 1 |
26 |
| - Explanation: There is one 0-diff pair in the array, (1, 1). |
27 |
| -
|
28 |
| - Note: |
29 |
| - The pairs (i, j) and (j, i) count as the same pair. |
30 |
| - The length of the array won't exceed 10,000. |
31 |
| - All the integers in the given input belong to the range: [-1e7, 1e7]. |
32 |
| - */ |
33 | 6 | public class _532 {
|
34 | 7 |
|
35 | 8 | public static class Solution1 {
|
|
0 commit comments