JAVA | 100 % TC | 100 % SC | Sorted Array
java\nclass Solution {\n    public List<Integer> findLonely(int[] nums) {\n        Arrays.sort(nums);\n        ArrayList<Integer> list = new ArrayList<>();\n   
```java\nclass Solution {\n    public List<Integer> findLonely(int[] nums) {\n        Arrays.sort(nums);\n        ArrayList<Integer> list = new ArrayList<>();\n        for (int i = 1; i < nums.length - 1; i++) {\n            if (nums[i - 1] + 1 < nums[i] && nums[i] + 1 < nums[i + 1]) {\n                list.add(nums[i]);\n            }\n        }\n        if (nums.length == 1) {\n            list.add(nums[0]);\n        }\n        if (nums.length > 1) {\n            if (nums[0] + 1 < nums[1]) {\n                list.add(nums[0]);\n            }\n            if (nums[nums.length - 2] + 1 < nums[nums.length - 1]) {\n                list.add(nums[nums.length - 1]);\n            }\n        }\n        return list;\n    }\n}\n```
['Array', 'Sorting', 'Java']