Guest User

Untitled

a guest
Jan 21st, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. #!/usr/bin/ruby
  2.  
  3. # "Cracking the Coding Interview, Fourth Edition"
  4. # 1.1 solution in Ruby
  5.  
  6.  
  7. def allUnique(s)
  8. seen = Hash.new()
  9. s.each_char do |c|
  10. if seen[c] then
  11. return false
  12. else
  13. seen[c] = true
  14. end
  15. end
  16. return true
  17. end
  18.  
  19. def allUniqueBit(s)
  20. seen = 2**129
  21. s.each_byte do |b|
  22. if 2**b | seen == seen
  23. return false
  24. else
  25. seen = seen | 2**b
  26. end
  27. end
  28. return true
  29. end
Add Comment
Please, Sign In to add comment