C++ without map Using sorting
The approach is pretty simple sort the array and then check for every index that its neigbhouring element is same or +1 of it or -1 of it . If this is true skip
The approach is pretty simple sort the array and then check for every index that its neigbhouring element is same or +1 of it or -1 of it . If this is true skip that element otherwise add it to the answer.\n```\nclass Solution {.\npublic:\n    vector<int> findLonely(vector<int>& nums) {\n        int c=0;\n        sort(nums.begin(),nums.end());\n        vector<int> ans;\n        if(nums.size()==1)\n            return nums;\n        if(nums[0]!=nums[1] && nums[0]+1 !=nums[1])\n            ans.push_back(nums[0]);\n        for(int i=1;i<nums.size()-1;i++){\n            if(nums[i]==nums[i+1] || nums[i]==nums[i-1] || nums[i]-1==nums[i-1] || nums[i]+1==nums[i+1]){\n                continue;\n            }else{\n                ans.push_back(nums[i]);\n            }\n        }\n        if(nums[nums.size()-1]!=nums[nums.size()-2] && nums[nums.size()-1]-1!=nums[nums.size()-2] )\n            ans.push_back(nums[nums.size()-1]);\n        return ans;\n    }\n};\n```
['Sorting']