C++ Solution || Well-Explained || Using Hash Table ✨✨
Intuition\nWe need to find lonely numbers in the given vector, where a lonely number is one that occurs exactly once and has no adjacent numbers in the vector.\
# Intuition\nWe need to find lonely numbers in the given vector, where a lonely number is one that occurs exactly once and has no adjacent numbers in the vector.\n\n# Approach\n1. Count the occurrences of each number in the vector using an unordered map.\n2. Iterate through the vector again and check if the current number occurs exactly once (i.e., its count is 1) and if both its adjacent numbers (nums[i]-1 and nums[i]+1) are not present in the map.\n3. If the above conditions are met, add the current number to the answer vector.\n4. Finally, return the answer vector containing the lonely numbers.\n\n# Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(n)\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> findLonely(vector<int>& nums) {\n        // count occur\n        unordered_map<int, int> mp;\n        for (int i = 0; i < nums.size(); i++) {\n            mp[nums[i]]++;\n        }\n\n        // check occur of nums[i]-1 and nums[i]+1\n        vector<int> ans;\n        for (int i = 0; i < nums.size(); i++) {\n            if ((mp[nums[i]] == 1) && (mp.find(nums[i] - 1) == mp.end()) && (mp.find(nums[i] + 1) == mp.end())) {\n                ans.push_back(nums[i]);\n            }\n        }\n\n        return ans;\n    }\n};\n```
['Array', 'Hash Table', 'Counting', 'C++']