daily pastebin goal
31%
SHARE
TWEET

Untitled

a guest Dec 15th, 2018 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution {
  2.     public List<String> findRepeatedDnaSequences(String s) {
  3.         ArrayList<String> list = new ArrayList<String>();
  4.         Map<String,Integer> stringMap = new HashMap<String,Integer>();
  5.         Set<String> ansSet = new HashSet<String>();
  6.         int length = s.length();
  7.         System.out.println(length);
  8.         for (int i= 0; i<length-9;i++) {
  9.            
  10.             String sub = s.substring(i, i+10);
  11.             if(stringMap.containsKey(sub)) {
  12.                 stringMap.put(sub,stringMap.get(sub)+1);
  13.                 ansSet.add(sub);
  14.             }else {
  15.                 stringMap.put(sub,1);
  16.             }
  17.            
  18.         }
  19.        
  20.         list.addAll(ansSet);
  21.         return list;
  22.     }
  23.  
  24. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top