Last active
August 29, 2015 14:21
Revisions
-
jmtame revised this gist
May 16, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # Very fast way to determine if a string contains all unique characters # Space O(1), Time O(N) # Assumes ASCII strings. Unicode would require space of Array.new(1,111,998). def is_unique(str) return false if str.length > 256 chars = Array.new(256) -
jmtame created this gist
May 16, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ # Very fast way to determine if a string contains all unique characters # Space O(1), Time O(N) # Assumes ASCII strings. Unicode would use this: chars = Array.new(1,111,998) def is_unique(str) return false if str.length > 256 chars = Array.new(256) str.each_byte.lazy.each do |c| return false if chars[c] chars[c] = true end true end