Skip to content

Instantly share code, notes, and snippets.

@spreered
Created September 13, 2017 07:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spreered/5df1ef1e029ab40ee831f777d43e4c57 to your computer and use it in GitHub Desktop.
Save spreered/5df1ef1e029ab40ee831f777d43e4c57 to your computer and use it in GitHub Desktop.
# @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