Description

Given an array nums, return all the lonely numbers. A number is lonely if it appears exactly once and neither x-1 nor x+1 appears in the array.

Examples

Input:nums = [10,6,5,8]
Output:[10,8]
Explanation:

10 and 8 have no adjacent values.

Input:nums = [2,3,4,5]
Output:[]
Explanation:

All numbers appear exactly once, but each has adjacent values: 2 has adjacent 3, 3 has adjacent 2 and 4, 4 has adjacent 3 and 5, and 5 has adjacent 4. No numbers are lonely.

Input:nums = [7,7,9,11,11,13]
Output:[9,13]
Explanation:

7 and 11 appear twice so they can't be lonely. 9 appears once and has no adjacent values (8 and 10 are not in the array). 13 appears once and has no adjacent values (12 and 14 are not in the array).

Constraints

  • 1 ≤ nums.length ≤ 10⁵

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!