Simple JAVA Solution


  • 0
    A
    public List<String> findRepeatedDnaSequences(String s) {
    	Set<String> dup = new HashSet<String>();
    	Set<String> set = new HashSet<String>();
    	int i = 0;
    	while (i <= s.length() - 10) {
    		String seq = s.substring(i, i + 10);
    		if (set.contains(seq))
    			dup.add(seq);
    		set.add(seq);
    		i++;
    	}
    	return new ArrayList(dup);
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.