Skip to content

Instantly share code, notes, and snippets.

@BiruLyu
Created May 22, 2017 16:59
Show Gist options
  • Save BiruLyu/08a6414f0b55d6b27afcdc0e7db8144f to your computer and use it in GitHub Desktop.
Save BiruLyu/08a6414f0b55d6b27afcdc0e7db8144f to your computer and use it in GitHub Desktop.
public class Solution {
public List<String> findRepeatedDnaSequences(String s) {
List<String> res = new LinkedList<String>();
Set<String> explored = new HashSet<String>();
Set<String> repeat = new HashSet<String>();//avoid repetition in res
for( int i = 0; i < s.length() - 9; i++){
String temp = s.substring(i,i + 10);
if(!explored.add(temp) && repeat.add(temp)){
res.add(temp);
}
}
return res;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment