Skip to content

Commit b86b974

Browse files
committed
532_K-diff_Pairs_in_an_Array
1 parent 0eeefe9 commit b86b974

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ I have solved quite a number of problems from several topics. See the below tabl
196196
|84| **[1438. Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit](https://tinyurl.com/yysmvobr)** | [Python](https://tinyurl.com/wu6rdaw/1438_Longest_Continuous_Subarray_With_Absolute_Diff_Less_Than_or_Equal_to_Limit.py), [Swift](https://tinyurl.com/wuja3c4/1438_Longest_Continuous_Subarray_With_Absolute_Diff_Less_Than_or_Equal_to_Limit.swift) | (Art 1)[https://tinyurl.com/y69hjhjp], (Art 2)[https://tinyurl.com/y3h2fj2m] | Medium | Sliding window |
197197
|85| **[1428. Leftmost Column with at Least a One](https://tinyurl.com/y3reu3y2)** | [Python](https://tinyurl.com/wu6rdaw/1428_Leftmost_Column_with_at_Least_a_One.py), [Swift](https://tinyurl.com/wuja3c4/1428_Leftmost_Column_with_at_Least_a_One.swift) | --- | Medium | Binary Search |
198198
|86| **[914. X of a Kind in a Deck of Cards](https://tinyurl.com/y39y2k32)** | [Python](https://tinyurl.com/wu6rdaw/914_X_of_a_Kind_in_a_Deck_of_Cards.py), [Swift](https://tinyurl.com/wuja3c4/914_X_of_a_Kind_in_a_Deck_of_Cards.swift) | --- | Easy (Not So) | |
199-
|87| **[1275. Find Winner on a Tic Tac Toe Game](https://tinyurl.com/y323arde)** | [Python](https://tinyurl.com/wu6rdaw/1275_Find_Winner_on_a_Tic_Tac_Toe_Game.py), [Swift](https://tinyurl.com/wuja3c4/1275_Find_Winner_on_a_Tic_Tac_Toe_Game.swift) | Art 1](https://tinyurl.com/yyc54qj5) | Easy (Not So) | |
199+
|87| **[1275. Find Winner on a Tic Tac Toe Game](https://tinyurl.com/y323arde)** | [Python](https://tinyurl.com/wu6rdaw/1275_Find_Winner_on_a_Tic_Tac_Toe_Game.py), [Swift](https://tinyurl.com/wuja3c4/1275_Find_Winner_on_a_Tic_Tac_Toe_Game.swift) | [Art 1](https://tinyurl.com/yyc54qj5) | Easy (Not So) | |
200+
|88| **[532. K-diff Pairs in an Array](https://tinyurl.com/yyrhmynd)** | [Python](https://tinyurl.com/wu6rdaw/532_K-diff_Pairs_in_an_Array.py), [Swift](https://tinyurl.com/wuja3c4/532_K-diff_Pairs_in_an_Array.swift) | [Art 1](https://tinyurl.com/y5tg5aqd) | Medium | |
200201

201202

202203
</p>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
func findPairs(_ nums: [Int], _ k: Int) -> Int {
3+
var counter = [Int:Int]()
4+
for num in nums {
5+
counter[num, default: 0] += 1
6+
}
7+
8+
var result = 0
9+
for (key, value) in counter {
10+
if k == 0 {
11+
if value > 1 {
12+
result += 1
13+
}
14+
} else if let count = counter[key + k] {
15+
result += 1
16+
}
17+
}
18+
return result
19+
}
20+
}

0 commit comments

Comments
 (0)