Why do I exceed the RAM limit?


  • 0
    E

    I can't figure out the "why". I had tried. Crying.

    	List<String> findRepeatedDnaSequences = new ArrayList<String>();
    	if (s == null)
    		return findRepeatedDnaSequences;
    
    	final int DNA = s.length();
    	final int repeatLength = 10;
    	final int shift = 2;
    
    	Map<Byte, Byte> converterL2N = new HashMap<Byte, Byte>();
    	Map<Byte, String> converterN2L = new HashMap<Byte, String>();
    	Set<Integer> totalNucleotidesSet = new HashSet<Integer>();
    	Set<Integer> repeatedNucleotidesSet = new HashSet<Integer>();
    
    	converterL2N.put((byte) 'A', (byte) 0);
    	converterL2N.put((byte) 'C', (byte) 1);
    	converterL2N.put((byte) 'G', (byte) 2);
    	converterL2N.put((byte) 'T', (byte) 3);
    
    	converterN2L.put((byte) 0, "A");
    	converterN2L.put((byte) 1, "C");
    	converterN2L.put((byte) 2, "G");
    	converterN2L.put((byte) 3, "T");
    
    	for (int index = 0; index < DNA - repeatLength; index++) {
    		int DNA_SEGMENT = 0;
    
    		for (int i = index; i < index + repeatLength; i++) {
    			DNA_SEGMENT <<= shift;
    			DNA_SEGMENT |= converterL2N.get((byte) s.charAt(i));
    		}
    
    		if (totalNucleotidesSet.contains(DNA_SEGMENT))
    			repeatedNucleotidesSet.add(DNA_SEGMENT);
    		else
    			totalNucleotidesSet.add(DNA_SEGMENT);
    	}
    
    	for (int entry : repeatedNucleotidesSet) {
    		String pattern = new String();
    		for (int i = 0; i < repeatLength; i++) {
    			byte filter = (byte) (entry & 0b11);
    			entry >>= shift;
    			pattern = converterN2L.get(filter) + pattern;
    		}
    		findRepeatedDnaSequences.add(pattern);
    	}
    
    	return findRepeatedDnaSequences;

  • 0
    O

    Does this give the specific case which causes the "Memory exceeds limit error"? If not, then it may be some issue with the compiler. Try replacing "0b11" with some binary or hex number that fill all 32 bits of an integer.


Log in to reply
 

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