func findRepeatedDnaSequences(s string) []string {
arr := make([]byte, len(s))
for i, v := range s {
switch string(v) {
case "A":
arr[i] = 0
case "C":
arr[i] = 1
case "G":
arr[i] = 2
case "T":
arr[i] = 3
}
}
left, right := 0, 0
var res []string
resMap := map[string]struct{}{}
seek := map[int]bool{}
tmp := 0
for right < len(arr) {
tmp = addNewStr(tmp, arr[right])
right++
for right-left >= 10 {
if _, exist := seek[tmp]; exist {
resMap[s[left:right]] = struct{}{}
} else {
seek[tmp] = true
}
left++
}
}
for key := range resMap {
res = append(res, key)
}
return res
}
func addNewStr(num int, b byte) int {
num = num << 2
num = num & 0xfffff
num = num | int(b)
return num
}
go语言解决重复的DNA序列问题,感谢大佬提供的思路