Find All Lonely Numbers in the Array
You are given an integer array nums. A number x is lonely when it appears only once, and no adjacent numbers (i.e. x + 1 and x - 1) appear in the array.
Return all lonely numbers in nums. You may return the answer in any order.
Example 1
Input
nums = [10,6,5,8]Output
[10,8]10 and 8 each appear exactly once and neither adjacent value appears in nums, while 5 and 6 are adjacent to each other.
Example 2
Input
nums = [1,3,5,3]Output
[1,5]1 and 5 each appear exactly once and neither adjacent value appears in nums, while 3 appears twice.
Constraints
- 1 <= nums.length <= 10^5
- 0 <= nums[i] <= 10^6