I don't know the reason of memory limit Java


  • 0
    R
    public class Solution {
    
    	public List<String> findRepeatedDnaSequences(String s) {
    		HashSet<BitSet> Subs=new HashSet<BitSet>();
    		HashSet<BitSet> Counted=new HashSet<BitSet>();
    		String orginal=s;
    		s=transformstring(s);
    		List<String> repeattedSet=new LinkedList<String>();
            for (int i=0;i<s.length()-20;i+=2) 
            {
            	String temp=s.substring(i,i+20);
            	BitSet tobitset=ToBits(temp);
            	if (Subs.contains(tobitset) && ! Counted.contains(tobitset)) {
            		Counted.add(tobitset);
            		repeattedSet.add(orginal.substring(i/2,i/2+10));
            	} else {
            		Subs.add(tobitset);
            	}
            }
            return repeattedSet;
        }
    	
    	public BitSet ToBits(String s) {
    		BitSet temp=new BitSet(s.length());
    		for(int i=0; i<s.length(); i++) {
    		    if( s.charAt(i) == '1' )
    		      temp.set( i );
    		  }
    		return temp;
    	}
    	
    	public String transformstring (String s) {
    		s=s.replaceAll("A", "00");
    		s=s.replaceAll("C", "10");
    		s=s.replaceAll("T", "01");
    		s=s.replaceAll("G", "11");
    		return s;
    	}
    }
    

    Everything seems normal. I changed it to binary. But still memory limit


Log in to reply
 

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