Find All Lonely Numbers in the Array LeetCode solution in C++

1
class Solution {
2
public:
3
vector<int> findLonely(vector<int> &nums) {
4
int n = nums.size();
5
unordered_map<int, int> ump;
6
vector<int> sol;
7
for (int i = 0; i < n; i++) {
8
ump[nums[i]]++;
9
}
10
for (auto a : ump) {
11
if (a.second == 1 and !ump.count(a.first + 1) and !ump.count(a.first - 1))
12
sol.push_back(a.first);
13
}
14

15
return sol;
16
}
17
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0