文章 224
评论 6
浏览 200766
Subsequence - 187. Repeated DNA Sequences

Subsequence - 187. Repeated DNA Sequences

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.

思路:

题目意思是找出重复的序列,采用滑动窗口和hashset不可以重复的特性来做。

代码:

java:

class Solution {

    public List<String> findRepeatedDnaSequences(String s) {
        Set curr = new HashSet(), repeated = new HashSet();
        for (int i = 0; i + 9 < s.length(); i++) {
            String ten = s.substring(i, i + 10);
            if (!curr.add(ten))
                repeated.add(ten);
        }
        return new ArrayList(repeated);
    }
}

标题:Subsequence - 187. Repeated DNA Sequences
作者:michael
地址:https://www.bitbo-liuyang.com/articles/2019/07/24/1563977633702.html

Nothing just happens, it's all part of a plan.

取消