JAVA Simple 8 Lines


  • 0
    P

    Spoiler
    public class Solution {
    public List<String> findRepeatedDnaSequences(String s) {
    List <String> l = new ArrayList<String>();
    if(s.length()<=10) return l;
    HashSet<String> h = new HashSet<String> ();
    for(int i=0; i<=s.length()-10; i++) {
    String temp = s.substring(i, i+10);
    if(!h.contains(temp)) {
    h.add(temp);
    }
    else if(!l.contains(temp)) {
    l.add(temp);
    }
    }
    return l;
    }
    }


Log in to reply
 

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