Without Map Approach || Beats 100%
Given\nWe are given an integer array nums. A number x is considered lonely when it appears only once in the array, and no adjacent numbers (i.e., x + 1 and x - 
# Given\nWe are given an integer array **nums**. A number **x** is considered lonely when it appears only once in the array, and no adjacent numbers (i.e., x + 1 and x - 1) are present in the array.\n\n# Approach\n- Solving this problem involves sorting the array and then iterating through it to find lonely numbers.\n- Compare each element with its adjacent elements to determine if it is lonely. \n- If a number appears only once and has no adjacent numbers, it is considered lonely and added to the result vector.\n\n# Explanation \n\n1. If the size of **nums** is **1** , there are no lonely numbers, so return **nums** as is.\n2. **Sort** the input vector **nums** in ascending order.\n3. Initialize an empty vector **lonely** to store the lonely numbers.\n4. Iterate through each element of the sorted vector nums.\n5. Check conditions based on the index i:\n- **i)** If **i** is not the first or last element, check if the **difference between the left and right elements compared to the current element is greater than 1**. If so, it\'s a lonely number, and add it to the ans.\n- **ii)** If **i** is the last element, check if the difference between the **current element and the previous element** is greater than 1. If so, it\'s a lonely number, and add it to the ans.\n- **iii)** If **i** is the first element, check if the **difference between the next element and the current element is greater than 1. **If so, it\'s a lonely number, and add it to the ans.\n6. Return the vector ans containing the lonely numbers.\n\n# Complexity\n- Time complexity: **O(n log n)** due to the sorting operation.\n\n- Space complexity: **O(n)** for the result vector.\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> findLonely(vector<int>& nums) {\n        // If the size is 1, return the input nums as there are no lonely numbers.\n        if(nums.size()<=1)\n            return nums;\n        // Sort the input vector in ascending order so you can compare ajacent elements.\n        sort(nums.begin(),nums.end());\n\n        vector<int> lonely;\n        int n = nums.size();\n        for(int i = 0; i < n; i++){\n\n            // If the current element is not the first or last element\n            if(i && i<n-1){\n            // check if the diff. between the left element ,right element compared to curr element is greater than 1.\n                if(nums[i]-nums[i-1]>1 && nums[i+1]-nums[i]>1){\n                    lonely.push_back(nums[i]);\n                }\n            }else if(i){    //If the current element is the last element\n                            //For the last element check if the diff b/w the previous element is greater than 1\n                if((nums[i]-nums[i-1])>1){\n                    lonely.push_back(nums[i]);\n                }\n            }else{  //If the current element is the first element\n                    //For the first element check if the diff b/w the next element is greater than 1\n                if((nums[i+1]-nums[i])>1){\n                    lonely.push_back(nums[i]);\n                }\n            }\n        }\n        return lonely;\n    }\n};\n```
['C++']