I was looking for a solution to find duplicate characters in a string and I was interested in a solution with bitwise operations.
I found such a variant with bitwise operations. But in it, the search occurs in the range a-z of the ASCII table.
func HasDuplicates(str string) (string, bool) {
checker := 0
for _, char := range str {
val := char - 'a'
fmt.Println(val)
if (checker & (1 << val)) > 0 {
fmt.Printf("'%c' is Duplicate\n", char)
return str, false
}
checker |= 1 << val
}
return str, true
}
Is it possible to make a universal solution, like the example above, only for a random unicode string (hieroglyphs, emoji, etc.)?