Leetcode

Leetcode 187. Repeated DNA Seque

2018-09-07  本文已影响3人  SnailTyan

文章作者: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/
上一篇下一篇

猜你喜欢

热点阅读