leetcode187. Repeated DNA Sequences

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode187. Repeated DNA Sequences相关的知识,希望对你有一定的参考价值。

 
 
位运算大法好
值得注意 例如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的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode-187. Repeated DNA Sequences

Leetcode 187 Repeated DNA Sequences

[LeetCode] 187. Repeated DNA Sequences

LeetCode 187. Repeated DNA Sequences 20170706 第三十次作业

187. Repeated DNA Sequences

LeetCode 187. Repeated DNA Sequences(位运算,hash)