Memory exceeded? My solution is only O(n) space


  • 1
    S
    public class Solution {
        public List<String> findRepeatedDnaSequences(String s) {
            HashSet<Integer> myMap = new HashSet<Integer>();
            HashSet<String> uniqueSequence = new HashSet<String>();
            List<String> result = new ArrayList<String>();
            
            if (s == null) {
                return result;
            }
            
            for (int i = 0; i <= s.length() - 10; i++) {
                String sequence = s.substring(i, i + 10);
                int hashCode = sequence.hashCode();
                if (!myMap.contains(hashCode)) {
                    myMap.add(hashCode);
                }
                else {
                    uniqueSequence.add(sequence);
                }
            }
            
            for (String DNA : uniqueSequence) {
                result.add(DNA);
            }
            
            return result;
        }
    }

  • 0

    Might just be because of your bug. Try input "AAAAAAAAAAAAAA".


  • 0
    S

    Yes, I modified the code a little bit. Still get the memory exceed limit.......


  • 0

    Please try submitting again, I have removed the memory limit on the judge side.


Log in to reply
 

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