2150. Find All Lonely Numbers in the Array (Medium) - TengnanYao/daily_leetcode GitHub Wiki

class Solution:
    def findLonely(self, nums: List[int]) -> List[int]:
        s = Counter(nums)
        result = []
        for num in nums:
            if num + 1 not in s and num - 1 not in s and s[num] == 1:
                result.append(num)
        return result