Memory limit exceeded for Repeated DNA sequence


  • 0
    J

    Getting memory limit exceeded.. used one space for storing answer.. one for int hash and some constant space

    class Solution {
    public:
    vector<string> findRepeatedDnaSequences(string s) {
        vector<string> res;
        set<int> hassh;
        map<char, int> mp;
        mp['A'] = 0;
        mp['C'] = 1;
        mp['G'] = 2;
        mp['T'] = 3;
        int len = s.size();
        for(int i = 0; i < len-10; ++i) {
            int cur = 0;
            for(int j = i; j < i+10; ++j) {
                cur += mp[s[i]];
                cur <<= 2;
            }
            if(hassh.count(cur) > 0)
                res.push_back(s.substr(i, 10));
            else
                hassh.insert(cur);
        }    
        return res;
    }
    };
    

  • 0
    J

    double check your loops, and your runtime


  • 0

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


  • 0
    J

    now it is showing output limit exceeded

    https://leetcode.com/submissions/detail/43449659/


Log in to reply
 

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