-2

Given a list of integers, I need to find the closests numbers to each other inside the list

>> [1,9,5,45,80,2]
>> closest(lst)
>> 1,2

Is there any quick way to do this?

1 Answers1

1
  • Sort the list
  • Subtract adjacent elements
  • Take the minimum of those differences
Prune
  • 76,765
  • 14
  • 60
  • 81