/* * 187. Repeated DNA Sequences * 2016-6-4 by Mingyang * 简单的hashmap,注意修改一个hashmap的方法,直接map.put(temp,false)就好了 */ public static ListfindRepeatedDnaSequences(String s) { List res=new ArrayList (); int len=s.length(); if(len<10) return res; HashMap map=new HashMap (); 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; }