The DNA sequence is composed of a series of nucleotides abbreviated as 'A', 'C', 'G', and 'T'.
When studying DNA, it is useful to identify repeated sequences within the DNA.
Given a string s that represents a DNA sequence, return all the 10-letter-long sequences (substrings) that occur more than once in a DNA molecule. You may return the answer in any order.
Example 1:
Example 2:
public List<String> findRepeatedDnaSequences(String s) {
int len = 0;
if(s == null || s.isBlank() || (len = s.length()) < 10 || len > 100000) {
return Collections.emptyList();
}
Set<String> ss = new HashSet<>(), res = new HashSet<>();
for(int i = 0; i <= len - 10; i++) {
String t = s.substring(i, i + 10);
if(!ss.add(t)){
res.add(t);
}
}
return new ArrayList<>(res);
}