Advertisement
DeepRest

Find All Lonely Numbers in the Array

Jan 23rd, 2022
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.30 KB | None | 0 0
  1. class Solution:
  2.     def findLonely(self, nums: List[int]) -> List[int]:
  3.         nums.sort()
  4.         n = len(nums)
  5.         ans = []
  6.         for i in range(n):
  7.             if (i==0 or nums[i]-nums[i-1] > 1) and (i==n-1 or nums[i+1]-nums[i] > 1):
  8.                 ans.append(nums[i])
  9.         return ans
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement