1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-14 09:59:41 +01:00
LeetCode/problems/contains-duplicate.rb

28 lines
616 B
Ruby
Raw Normal View History

# @param {Integer[]} nums
# @return {Boolean}
def contains_duplicate(nums)
encountered = Set.new
nums.each { |x|
if encountered.add?(x) == nil then
return true
end
}
return false
end
RSpec.describe "contains_duplicate" do
it "nums = [1,2,3,1] contains" do
expect(contains_duplicate([1,2,3,1])).to be true
end
it "nums = [1,2,3,4] doesn't contain" do
expect(contains_duplicate([1,2,3,4])).to be false
end
it "nums = [1,1,1,3,3,4,3,2,4,2] contains" do
expect(contains_duplicate([1,1,1,3,3,4,3,2,4,2])).to be true
end
end