Wired: compile error but no error message


  • 0
    A

    I constantly get compile error (no error message) for the following code submission:

    class Solution {

    public:
        size_t numDistinct(const string& S, const string& T) {
            const size_t m = S.size();
            const size_t n = T.size();
    
            if (n>m) {
                return 0;
            }
    
            if (n == 0) {
                return 1;
            }
    
            vector<vector<size_t>> res(1+m, vector<size_t>(1+n));
            for (size_t i = 0; i<=m; ++i) {
                res[i][n] = 1;
            }
            
            for (size_t i = 0; i<n; ++i) {
                res[m][i] = 0;
            }
            
            for (size_t i = m; i>0; --i) {
                for (size_t j = n; j>0; --j) {
                    res[i-1][j-1] = res[i][j-1];
                    if (S[i-1] == T[j-1]) {
                        res[i-1][j-1] += res[i][j];
                    }
                }
            }
            
            return res[0][0];
        }
    };
    

    The code compiles fine locally on my own machine.


  • 0

    Your function signature is incorrect. It should be

    int numDistinct(string S, string T)

  • 0
    A

    I see. Thanks. But this is still wired~~~, since the signature I was writing is reasonable for the problem and more C++-ish. Do the two signatures
    int numDistinct(string S, string T)
    size_t numDistinct(const string& S, const string& T)
    have any significant difference to OJ compiler?


  • 0
    K

    dude, it's weird.


Log in to reply
 

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