Simple solution to avoid MLE

  • 0

    vector<string> findRepeatedDnaSequences(string s) {
    map<long,int> mp;
    vector<string> v;
    if (s.size()<=10) return v;
    for(int i=0;i<s.size()-9;i++) {
    string sub=s.substr(i,10);
    for(char &c : sub) {
    switch(c) {
    case 'A':c='0';break;
    case 'C':c='1';break;
    case 'G':c='2';break;
    case 'T':c='3';break;
    long l=stol(sub);
    if (mp[l]==2) v.push_back(s.substr(i,10));
    return v; }

Log in to reply

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