1. <strong id="7actg"></strong>
    2. <table id="7actg"></table>

    3. <address id="7actg"></address>
      <address id="7actg"></address>
      1. <object id="7actg"><tt id="7actg"></tt></object>

        ?LeetCode刷題實(shí)戰(zhàn)187:重復(fù)的DNA序列

        共 880字,需瀏覽 2分鐘

         ·

        2021-02-18 14:10

        算法的重要性,我就不多說(shuō)了吧,想去大廠,就必須要經(jīng)過(guò)基礎(chǔ)知識(shí)和業(yè)務(wù)邏輯面試+算法面試。所以,為了提高大家的算法能力,這個(gè)公眾號(hào)后續(xù)每天帶大家做一道算法題,題目就從LeetCode上面選 !

        今天和大家聊的問(wèn)題叫做?重復(fù)的DNA序列?,我們先來(lái)看題面:
        https://leetcode-cn.com/problems/reverse-words-in-a-string-ii/

        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.

        題意


        所有 DNA 都由一系列縮寫(xiě)為 'A','C','G' 和 'T' 的核苷酸組成,例如:"ACGAATTCCG"。在研究 DNA 時(shí),識(shí)別 DNA 中的重復(fù)序列有時(shí)會(huì)對(duì)研究非常有幫助。

        編寫(xiě)一個(gè)函數(shù)來(lái)找出所有目標(biāo)子串,目標(biāo)子串的長(zhǎng)度為 10,且在 DNA 字符串 s 中出現(xiàn)次數(shù)超過(guò)一次。

        示例


        示例 1

        輸入:s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT"
        輸出:["AAAAACCCCC","CCCCCAAAAA"]


        示例 2

        輸入:s = "AAAAAAAAAAAAA"
        輸出:["AAAAAAAAAA"]

        提示:

        0?<= s.length <= 105
        s[i] 為 'A''C'、'G'?或 'T'


        解題


        思路分析:利用map標(biāo)記各個(gè)長(zhǎng)度為10的子串出現(xiàn)的次數(shù),出現(xiàn)多次的就是結(jié)果。C++代碼如下:

        class?Solution?{
        public:
        ??vector<string> findRepeatedDnaSequences(string?s) {
        ????vector<string> result;
        ????unordered_map<string, int> myMap;//用于關(guān)聯(lián)各個(gè)長(zhǎng)度為10的子串出現(xiàn)的次數(shù)
        ????int?strSize = s.size();
        ????for?(int?beginIndex = 0; beginIndex <= strSize - 10; ++beginIndex) {
        ??????string?tempRes = s.substr(beginIndex, 10);
        ??????if?(++myMap[tempRes] == 2) {//第一次出現(xiàn)兩次,避免重復(fù)
        ????????result.push_back(tempRes);
        ??????}
        ????}
        ????return?result;
        ??}
        };



        好了,今天的文章就到這里,如果覺(jué)得有所收獲,請(qǐng)順手點(diǎn)個(gè)在看或者轉(zhuǎn)發(fā)吧,你們的支持是我最大的動(dòng)力 。

        上期推文:

        LeetCode1-180題匯總,希望對(duì)你有點(diǎn)幫助!
        LeetCode刷題實(shí)戰(zhàn)181:超過(guò)經(jīng)理收入的員工
        LeetCode刷題實(shí)戰(zhàn)182:查找重復(fù)的電子郵箱
        LeetCode刷題實(shí)戰(zhàn)183:從不訂購(gòu)的客戶
        LeetCode刷題實(shí)戰(zhàn)184:部門(mén)工資最高的員工
        LeetCode刷題實(shí)戰(zhàn)185:部門(mén)工資前三高的所有員工
        LeetCode刷題實(shí)戰(zhàn)186:翻轉(zhuǎn)字符串里的單詞 II

        瀏覽 36
        點(diǎn)贊
        評(píng)論
        收藏
        分享

        手機(jī)掃一掃分享

        分享
        舉報(bào)
        評(píng)論
        圖片
        表情
        推薦
        點(diǎn)贊
        評(píng)論
        收藏
        分享

        手機(jī)掃一掃分享

        分享
        舉報(bào)
        1. <strong id="7actg"></strong>
        2. <table id="7actg"></table>

        3. <address id="7actg"></address>
          <address id="7actg"></address>
          1. <object id="7actg"><tt id="7actg"></tt></object>
            久久黄色视| 中文字幕乱码亚洲精品一区 | 美女色免费av | 黄色操逼视频在线观看 | 在线免费观看a | 亚洲自拍偷拍视频 | 欧美5o607o | 久久久久久久久黄色 | 一级性生活片免费看 | 国产精品福利在线观看 |