Created
September 9, 2016 15:43
-
-
Save ProfessorSalty/1cc64b50169703e425de5226e373118a to your computer and use it in GitHub Desktop.
Find the integer with an odd number of occurrences
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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