1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-09-16 16:36:56 +02:00
LeetCode/rb/contains-duplicate.rb
Matej Focko 2351dfd0ee
chore: unwrap one layer
Signed-off-by: Matej Focko <mfocko@redhat.com>
2023-12-12 14:36:00 +01:00

27 lines
616 B
Ruby

# @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