Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/ruby
- # "Cracking the Coding Interview, Fourth Edition"
- # 1.1 solution in 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
Add Comment
Please, Sign In to add comment