美文网首页Leetcode
Leetcode 187. Repeated DNA Seque

Leetcode 187. Repeated DNA Seque

作者: SnailTyan | 来源:发表于2018-09-07 20:49 被阅读3次

    文章作者:Tyan
    博客:noahsnail.com  |  CSDN  |  简书

    1. Description

    Repeated DNA Sequences

    2. Solution

    class Solution {
    public:
        vector<string> findRepeatedDnaSequences(string s) {
            vector<string> result;
            map<string, int> mapping;
            int length = s.length();
            for(int i = 0; i < length - 9; i++) {
                string substr = s.substr(i, 10);
                mapping[substr]++;
                if(mapping[substr] == 2) {
                    result.push_back(substr);
                }
            }
            return result;
        }
    };
    

    Reference

    1. https://leetcode.com/problems/repeated-dna-sequences/description/

    相关文章

      网友评论

        本文标题:Leetcode 187. Repeated DNA Seque

        本文链接:https://www.haomeiwen.com/subject/crpqgftx.html