• 187. Repeated DNA Sequences


    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.

    Example:

    Input: s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT"

    Output: ["AAAAACCCCC", "CCCCCAAAAA"]

    class Solution {
    public:
    vector findRepeatedDnaSequences(string s) {
    set set_res,sequences;
    int len = s.size();

        for(int i = 0; i + 9 < len; i++)
        {
            string temp = s.substr(i, 10);
            if(sequences.count(temp)) 
            {
                set_res.insert(temp);
            }
            else
            {
                sequences.insert(temp);
            }
        }
        
        return vector<string>(set_res.begin(), set_res.end());
    }
    

    };

    后续优化,采用bitmap的方式减少存储。。。。。

  • 相关阅读:
    02数值类型
    01开班第一节
    oracle 课堂笔记
    错题整理
    多线程下的单例模式
    线程的同步和异步
    九大内置对象!!!
    jsp前三章测试
    Jav开发中的23种设计模式详解(转载)
    java IO 学习笔记
  • 原文地址:https://www.cnblogs.com/qiaozhoulin/p/13376719.html
Copyright © 2020-2023  润新知