/* * 187. Repeated DNA Sequences * 2016-6-4 by Mingyang * 简单的hashmap,注意修改一个hashmap的方法,直接map.put(temp,false)就好了 */ public static List<String> findRepeatedDnaSequences(String s) { List<String> res=new ArrayList<String>(); int len=s.length(); if(len<10) return res; HashMap<String,Boolean> map=new HashMap<String,Boolean>(); int start=0; for(int i=10;i<=len;i++){ String temp=s.substring(start,i); if(map.containsKey(temp)&&(map.get(temp)==true)){ res.add(temp); map.put(temp,false); }else if(!map.containsKey(temp)){ map.put(temp,true); } start++; } return res; }