Skip to content

Instantly share code, notes, and snippets.

Created April 11, 2014 00:34
Show Gist options
  • Save anonymous/10434404 to your computer and use it in GitHub Desktop.
Save anonymous/10434404 to your computer and use it in GitHub Desktop.
"Implement an algorithm to determine if a string has all unique characters."
def is_str_unq(str)
h = {}
str.split("").each do |c|
if (h.has_key?(c))
return false
else
h[c] = 1
end
end
return true
end
puts is_str_unq(ARGV[0])
@baweaver
Copy link

def is_str_uniq(str)
  str.length - str.chars.uniq.join.length <= 0
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment