why Runtime Error ?


  • 0
    L

    When I run at dev-c++, it could work.
    When I use Run code , it could work.
    But when I use 'Submit solution', "Runtime Error" appear.
    Why?
    I will appreciate it if you help me.
    The follow is my code.
    ···
    /**

    • Return an array of size *returnSize.
    • Note: The returned array must be malloced, assume caller calls free().
      */
      char number[10][5] = {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
      char **st;
      int k = 0;

    void solve(const char* digits, char* to, int index) {
    if (digits[index] == '\0') {
    to[index] = '\0';
    strcpy(st[k++], to);
    return ;
    }
    int i;
    char* num = number[digits[index]-'0'];
    for (i = 0; num[i] != '\0'; ++i) {
    to[index] = num[i];
    solve(digits, to, index + 1);
    }
    }

    char** letterCombinations(char* digits, int* returnSize) {
    if (digits == NULL || *digits == '\0') {
    *returnSize = 0;
    return NULL;
    }
    int n = 1;
    int i;
    char *to;
    int digits_len = strlen(digits);

    for (i = 0; i < digits_len; ++i) {
        if (digits[i] == '7' || digits[i] == '9')
            n *= 4;
        else
            n *= 3;
    }
    *returnSize = n;
    st = (char**)malloc(sizeof(char*)*n);
    for (i = 0; i < n; ++i)
        st[i] = (char*)malloc(sizeof(char)*(digits_len+1));
    to = (char*)malloc(sizeof(char)*(digits_len+1));
    solve(digits, to, 0);
    free(to);
    return st;
    

    }
    ···


Log in to reply
 

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