当前位置: 代码迷 >> 综合 >> Leetcode 187. Repeated DNA Sequences
  详细解决方案

Leetcode 187. Repeated DNA Sequences

热度:62   发布时间:2023-12-12 21:21:43.0

文章作者: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/