2150. Find All Lonely Numbers in the Array

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 2150

class Solution:
    def findLonely(self, nums: List[int]) -> List[int]:
        counter = Counter(nums)
        res = []
        for num, cnt in counter.items():
            if cnt == 1 and counter[num - 1] == 0 and counter[num + 1] == 0:
                res.append(num)
        return res