Skip to content

Commit a65e13c

Browse files
committed
Solution as on 17-03-2022 10:02 pm
1 parent 2c89a82 commit a65e13c

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// 2150.✅ Find All Lonely Numbers in the Array
2+
3+
class Solution
4+
{
5+
public:
6+
vector<int> findLonely(vector<int> &nums)
7+
{
8+
map<int, int> m;
9+
vector<int> res;
10+
for (int i : nums)
11+
++m[i];
12+
13+
for (int i = 0; i < nums.size(); ++i)
14+
{
15+
if (m[nums[i]] == 1 && m.count(nums[i] - 1) == 0 && m.count(nums[i] + 1) == 0)
16+
res.push_back(nums[i]);
17+
}
18+
19+
return res;
20+
}
21+
};

0 commit comments

Comments
 (0)