[LeetCode] Repeated DNA Sequences
An intuitive solution would be traverse through the whole string,
create HashMap using key of every 10-letter-long substring.
But comparing 2 strings is slow, there are better ways.
Consider ACGT, there are only 4, therefore we can use 2 bit binary numbers to represent them.
That is to say: 00 for A, 01 for C, 10 for G, 11 for T.
For ACGT
, it will be 00011011
, for example.
Using this method, we are able to store the 10-letter-long substring using only 1 integer.
1 | class Solution: |