Skip to content

Instantly share code, notes, and snippets.

@infinitesteps
Created April 1, 2011 16:07
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 infinitesteps/898399 to your computer and use it in GitHub Desktop.
Save infinitesteps/898399 to your computer and use it in GitHub Desktop.
Cracking the Coding Interview, Fourth Edition
#!/usr/bin/ruby
def allUnique(s)
seen = Hash.new()
s.each_char do |c|
if seen[c] then
return false
else
seen[c] = true
end
end
return true
end
def allUniqueBit(s)
seen = 2**129
s.each_byte do |b|
if 2**b | seen == seen
return false
else
seen = seen | 2**b
end
end
return true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment