Skip to content

Instantly share code, notes, and snippets.

@ProfessorSalty
Created September 9, 2016 15:43
Show Gist options
  • Save ProfessorSalty/1cc64b50169703e425de5226e373118a to your computer and use it in GitHub Desktop.
Save ProfessorSalty/1cc64b50169703e425de5226e373118a to your computer and use it in GitHub Desktop.
Find the integer with an odd number of occurrences
array = [1,1,1,1,1,1,10,1,1,1,1,12,12,12]
def find_odd_integer(seq)
tmpDict = Hash.new 0
seq.each do |item|
tmpDict[item] += 1
end
tmpDict.select { |key, value| value % 2 ==1 }.keys
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment