Skip to content

Practice Find All Lonely Numbers in the Array

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2150
LeetCode Problem

Find All Lonely Numbers in the Array

Problem Statement

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.

Source: Find All Lonely Numbers in the Array on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

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

# Example 2

Input
nums = [1,3,5,3]
Output
[1,5]

Constraints

1 <= nums.length <= 10^5
0 <= nums[i] <= 10^6

Related LeetCode Problems

Practice more problems similar to Find All Lonely Numbers in the Array.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.