# 2150. Find All Lonely Numbers in the Array ###### tags: `Leetcode` `Medium` `HashMap` Link: https://leetcode.com/problems/find-all-lonely-numbers-in-the-array/description/ ## Code ```java= class Solution { public List<Integer> findLonely(int[] nums) { Map<Integer, Integer> cnt = new HashMap<>(); for(int num:nums){ cnt.put(num, cnt.getOrDefault(num, 0)+1); } List<Integer> ans = new ArrayList<>(); for(int num:nums){ if(cnt.get(num)==1 && !cnt.containsKey(num-1) && !cnt.containsKey(num+1)){ ans.add(num); } } return ans; } } ```