✅ Java || HashMap and Sorting Approaches || Easy To understand ✅
SOLUTION-1 (Using Sorting)\n## TC : O(nlogn)  SC : O(1)\n\npublic List<Integer> findLonely(int[] nums) {\n        Arrays.sort(nums);\n        \n        List<Int
# SOLUTION-1 (Using Sorting)\n## TC : O(nlogn)  SC : O(1)\n```\npublic List<Integer> findLonely(int[] nums) {\n        Arrays.sort(nums);\n        \n        List<Integer> ans = new ArrayList<>();\n        for(int i = 0;i < nums.length;i++){\n            if(i - 1 >= 0 && ( nums[i - 1] + 1 == nums[i] || nums[i - 1] == nums[i])){\n                continue;\n            }\n            \n            if(i + 1 <= nums.length - 1 && (nums[i + 1] == nums[i] + 1 || nums[i + 1] == nums[i])){\n                continue;\n            }\n            \n            ans.add(nums[i]);\n        }\n        \n        return ans;\n    }\n```\n\n# SOLUTION-2 (Using HashMap)\n## TC : O(n)   SC : O(n)\n\n```\npublic List<Integer> findLonely(int[] nums) {\n        HashMap<Integer,Integer> map = new HashMap<>();\n        \n        for(int i = 0;i < nums.length;i++){\n            if(map.containsKey(nums[i]))\n                map.put(nums[i],map.get(nums[i]) + 1);\n            else\n                map.put(nums[i],1);\n        }\n        \n        List<Integer> ans = new ArrayList<>();\n        for(int i = 0;i < nums.length;i++){\n            if(map.get(nums[i]) > 1 || map.containsKey(nums[i] + 1) || map.containsKey(nums[i] - 1))\n                continue;\n            \n            ans.add(nums[i]);\n        }\n        \n        return ans;\n    }\n```
['Sorting', 'Java']