You are given an integer array nums. A number x is lonely when it appears only once, and no adjacent numbers (i.e. x + 1 and x - 1) appear in the array.

Return all lonely numbers in nums. You may return the answer in any order.

&nbsp;
Example 1:

Input: nums = [10,6,5,8]
Output: [10,8]
Explanation: 
- 10 is a lonely number since it appears exactly once and 9 and 11 does not appear in nums.
- 8 is a lonely number since it appears exactly once and 7 and 9 does not appear in nums.
- 5 is not a lonely number since 6 appears in nums and vice versa.
Hence, the lonely numbers in nums are [10, 8].
Note that [8, 10] may also be returned.


Example 2:

Input: nums = [1,3,5,3]
Output: [1,5]
Explanation: 
- 1 is a lonely number since it appears exactly once and 0 and 2 does not appear in nums.
- 5 is a lonely number since it appears exactly once and 4 and 6 does not appear in nums.
- 3 is not a lonely number since it appears twice.
Hence, the lonely numbers in nums are [1, 5].
Note that [5, 1] may also be returned.


&nbsp;
Constraints:


	1 &lt;= nums.length &lt;= 105
	0 &lt;= nums[i] &lt;= 106


class Solution:
    def findLonely(self, nums: List[int]) -> List[int]:
        m = Counter(nums)
        return [n for n in nums if m[n] == 1 and m[n - 1] + m[n + 1] == 0]
class Solution {
    public List<Integer> findLonely(int[] nums) {
        Arrays.sort(nums);
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 1; i < nums.length - 1; i++) {
            if (nums[i - 1] + 1 < nums[i] && nums[i] + 1 < nums[i + 1]) {
                list.add(nums[i]);
            }
        }
        if (nums.length == 1) {
            list.add(nums[0]);
        }
        if (nums.length > 1) {
            if (nums[0] + 1 < nums[1]) {
                list.add(nums[0]);
            }
            if (nums[nums.length - 2] + 1 < nums[nums.length - 1]) {
                list.add(nums[nums.length - 1]);
            }
        }
        return list;
    }
}
class Solution {
public:
    vector<int> findLonely(vector<int>& nums) {
        int n=nums.size();
        unordered_map<int,int> ump;
        vector<int> sol;
        for(int i=0;i<n;i++)
        {
            ump[nums[i]]++;
        }
        for(auto a: ump)
        {
            if(a.second==1 and !ump.count(a.first+1) and !ump .count(a.first-1))
                sol.push_back(a.first);
        }

        return sol;
    }
};
var findLonely = function(nums) {
    let countMap = new Map();
    let result = [];
    for (let num of nums) {
        countMap.set(num, (countMap.get(num) || 0) + 1);
    }
    for (let num of nums) {
        if (!countMap.has(num - 1) && !countMap.has(num + 1) && countMap.get(num) === 1) {

            result.push(num);
        }

    }
    return result;
};
Find All Lonely Numbers in the Array