LeetCode: Single Number II
Question
Given an integer array nums where every element appears three times except for one, which appears exactly once. Find the single element and return it.
Solution
def single_number(nums)
data_set = Hash.new(0)
nums.each do |num|
data_set[num] += 1
end
data_set.key(1)
end
Comments