[JAVA] easiest solution using HashMap
\n\n# Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your space complexity here, e.g. O(n) \n
\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public List<Integer> findLonely(int[] nums) {\n      Map<Integer, Integer> map = new HashMap<>();\n      for(int num : nums) {\n          map.put(num, map.getOrDefault(num, 0) + 1);\n      }\n      List<Integer> ans = new ArrayList<>();\n      for(int num : nums) {\n          if(map.get(num) == 1 && ! map.containsKey(num - 1) && ! map.containsKey(num + 1))\n          ans.add(num);\n      } \n      return ans;  \n    }\n}\n```\n# PLEASE UPVOTE IF IT WAS HELPFULL
['Java']