Skip to content

Instantly share code, notes, and snippets.

@spreered

spreered/Contains_Duplicate1.rb Secret

Created Sep 13, 2017
Embed
What would you like to do?
# @param {Integer[]} nums
# @return {Boolean}
def contains_duplicate(nums)
na = nums.sort
na.each_index do |i|
if i<na.length
return true if na[i]== na[i+1]
end
end
return false
end
def contains_duplicate(nums)
store = {}
nums.each do |num|
return true if store[num]
store[num] = true
end
return false
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment