self-explained and readable Java solution


  • 0
    X
    class Solution {
        public List<String> findRepeatedDnaSequences(String s) {
            Set st = new HashSet();
            int len = s.length();
            List<String> mylist = new ArrayList<String>();
            
            if(len<=10) return mylist;
            for(int i =0;i<len-9;i++)
                if(!st.add(s.substring(i,i+10))){
                         mylist.add(s.substring(i,i+10));
                }
            
            return mylist;
        }
    }
    

Log in to reply
 

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