Advertisement
nikunjsoni

532

Apr 18th, 2021
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.35 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     int findPairs(vector<int>& nums, int k) {
  4.         unordered_map<int, int> count;
  5.         for(int x: nums) count[x]++;
  6.        
  7.         int ans = 0;
  8.         for(auto x: count)
  9.             if((k>0 && count.count(x.first+k)) || (k == 0  && x.second > 1))
  10.                 ans++;
  11.        
  12.         return ans;
  13.     }
  14. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement