重复

http://www.lintcode.com/zh-cn/problem/repeated-dna/

import java.util.ArrayList;
import java.util.List;

public class Solution {
    /**
     * @param s: a string represent DNA sequences
     * @return: all the 10-letter-long sequences
     */
    public List findRepeatedDna(String s) {
        // write your code here
        List list = new ArrayList<>();
        for (int i = 0; i < s.length() - 10; i++) {
            String src = s.substring(i, i + 10);
            if (list.contains(src)) {
                continue;
            }
            int index = s.indexOf(src, i + 1);
            if (index > -1) {
                list.add(src);
            }
        }
        return list;
    }
}

你可能感兴趣的:(重复)