首页 > 代码库 > leetcode187. Repeated DNA Sequences

leetcode187. Repeated DNA Sequences

https://leetcode.com/problems/repeated-dna-sequences/#/description
 
https://leetcode.com/problems/repeated-dna-sequences/#/solutions
 
位运算大法好
值得注意 例如0xff 一个f表示15 二进制中表示1111
 
 1 class Solution {
 2 public:
 3     vector<string> findRepeatedDnaSequences(string s) {
 4         //A is 0101, C is 0103, G is 0107, T is 0124       //3bit to store 
 5         unordered_map<int,int> m;
 6         vector<string> r;
 7         int t=0,i=0,ss=s.length();
 8         while(i<9)
 9           t=t<<3|s[i++]&7;
10         while(i<ss)
11           if(m[t=t<<3&0x3fffffff|s[i++]&7]++==1)
12             r.push_back(s.substr(i-10,10));
13         return r;
14     }
15 };

 

leetcode187. Repeated DNA Sequences