← 返回 apple 的题目列表Numbers with No Neighbors
类型:qbank
Given an integer array nums, return every value n in nums that satisfies both conditions:.
Examples
Example 1:
Input: nums = [1, 3, 5, 7]
Output: [1, 3, 5, 7]
Explanation:
Every value is isolated (no adjacent value in the array) and appears exactly once.
Example 2:
Input: nums = [1, 2, 5, 7]
Output: [5, 7]
Explanation:
1 and 2 are neighbors of each other, so both are excluded. 5 and 7 each appear once with no neighbors in the array.
Example 3:
Input: nums = [4, 4, 7, 9]
Output: [7, 9]
Explanation:
4 appears twice (fails condition 1). 7 has no neighbors (6 and 8 are absent) and appears once. 9 has no neighbors (8 and 10 are absent) and appears once.
Constraints
0 <= nums.length <= 10^5
-10^9 <= nums[i] <= 10^9