lundi 31 août 2020

runtime error: addition of unsigned offset to 0x7ffeba23a6e0

Here is my code, I wrote it on leetcode platform

const int N1 = 100+1;
const int N2 = 10e4+1;
class Solution {
public:
    bool cache[N1][N2];
    bool isSubsequence(string s, string t) {
        int n1 = s.size();
        int n2 = t.size();
        for(int i=0; i<=n1; i++) {
            for(int j=0; j<=n2; j++) {
                if(i == 0)
                    cache[i][j] = true;
                if(j == 0)
                    cache[i][j] = false;
                if(s[i-1] == t[j-1])
                    cache[i][j] = cache[i-1][j-1];
                else
                    cache[i][j] = cache[i][j-1];
            }
        }
        return cache[n1][n2];
    }
};

It gives following error, I don't know why. Please help. error image

EDIT: (Solved issue):

if(i == 0)
   cache[i][j] = true;
else if(j == 0)
   cache[i][j] = false;
else if(s[i-1] == t[j-1])
   cache[i][j] = cache[i-1][j-1];
else
   cache[i][j] = cache[i][j-1];
};

Aucun commentaire:

Enregistrer un commentaire