2150. Find All Lonely Numbers in the Array
On This Page
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