国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

Leetcode 187 Repeated DNA Sequences

2019-11-08 02:27:47
字體:
供稿:網(wǎng)友

All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.

Write a function to find all the 10-letter-long sequences (substrings) that occur more than once in a DNA molecule.

For example,

Given s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT",Return:["AAAAACCCCC", "CCCCCAAAAA"].十個(gè)字符表示一個(gè)DNA序列,找出多次出現(xiàn)的序列。

移動(dòng)頭尾兩個(gè)指針,用map存儲(chǔ)已經(jīng)探測(cè)過的序列,當(dāng)該序列之前出現(xiàn)過一次的時(shí)候,則將它加入答案中。

在由前一個(gè)位置的序列得到下一個(gè)位置的序列時(shí)可以采用位運(yùn)算的方式。

對(duì)AGCT四個(gè)字母編碼,0,1,2,3,則兩個(gè)bit可以表示一個(gè)字母,十個(gè)字符正好20bit,可以用int類型表示。

移動(dòng)到下一位時(shí)用上一個(gè)位置的int值向高位移動(dòng)2bit,然后或上新的2bit,在與0xfffff求與保留低20位。

class Solution {public:    vector<string> findRepeatedDnaSequences(string s) {        vector<string> res;        if(s.size() < 10) return res;        unordered_map<int, int> mp;        unordered_map<char, int> id;        id['A'] = 0;        id['C'] = 1;        id['G'] = 2;        id['T'] = 3;        int temp = 0;        for(int i = 0; i < s.size(); i++)        {            temp = (temp<<2| (id[s[i]] & 3)) & 0xfffff;            if(i > 8)            {                if(mp[temp] == 1) res.push_back(s.substr(i - 9,10));                mp[temp]++;            }        }        return res;    }};


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 法库县| 乌兰县| 静乐县| 加查县| 元江| 响水县| 凤城市| 门头沟区| 六安市| 荥经县| 新建县| 新晃| 铜川市| 南汇区| 伊宁市| 缙云县| 晋宁县| 富阳市| 金塔县| 新绛县| 远安县| 合江县| 湛江市| 同心县| 陇南市| 富蕴县| 军事| 铁岭县| 亳州市| 宁夏| 鄯善县| 舒兰市| 天柱县| 张家川| 山丹县| 望都县| 交口县| 苏尼特右旗| 三原县| 临高县| 凌云县|