Last active
October 3, 2019 22:01
-
-
Save piontekle/ed7bdacfe86e613a2608bcbfd30ba526 to your computer and use it in GitHub Desktop.
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
=begin | |
Given an array, find the int that appears an odd number of times. | |
There will always be only one integer that appears an odd number of times. | |
967 ms | |
=end | |
def find_it(seq) | |
#your code here | |
counts = Hash.new(0) | |
seq.each { |num| counts[num] += 1 } | |
counts.each_key { |key| return key if counts[key] % 2 != 0 } | |
end | |
#814ms | |
def find_it(seq) | |
seq.find { |n| seq.count(n).odd? } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment