Skip to content

Commit 104284e

Browse files
🐎 Day 3
1 parent 693d6ae commit 104284e

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
1. [Number of Recent Calls](https://leetcode.com/explore/challenge/card/october-leetcoding-challenge/559/week-1-october-1st-october-7th/3480/) ➡️ [CPP Solution](Week1/RecentCounter.cpp)
1010
2. [Combination Sum](https://leetcode.com/explore/challenge/card/october-leetcoding-challenge/559/week-1-october-1st-october-7th/3481/) ➡️ [CPP Solution](Week1/combinationSum.cpp)
11+
3. [K-diff Pairs in an Array](https://leetcode.com/explore/challenge/card/october-leetcoding-challenge/559/week-1-october-1st-october-7th/3482/) ➡️ [CPP Solution](Week1/findPairs.cpp)
1112

1213
## Week 2 🚧
1314

Week1/findPairs.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public:
3+
int findPairs(vector<int>& nums, int k) {
4+
unordered_map<int, int> m;
5+
int n = nums.size();
6+
int count = 0;
7+
8+
if(n <= 1) return count;
9+
10+
for(int num: nums)
11+
m[num]++;
12+
13+
for(auto &x: m) {
14+
if((k == 0 && x.second > 1) || (k > 0 && m.find(x.first - k) != m.end())) count++;
15+
}
16+
17+
return count;
18+
}
19+
};

0 commit comments

Comments
 (0)