the same code,the same input,but the result of run code and submit is different. it's why?


  • 0
    Y

    code:
    '''
    char** letterCombinations(char* digits, int* returnSize) {
    int i, j, k = 1, top, count, t, s = 1, h, len;
    char *temp;
    char *nums[10] = {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};

    len = strlen(digits);
    if(0 == len){
        *returnSize = 0;
        return NULL;
    }
    
    int *num = (int *)malloc(sizeof(int) * len);
    for(i = 0; i < len; ++i){
        if(('0' == digits[i]) || ('1' == digits[i]))
            return NULL;
        else if(('9' == digits[i]) || ('7' == digits[i]))
            num[i] = 4;
        else
            num[i] = 3;
        k *= num[i];
    }
    
    count = i;
    char **str = (char **)malloc(sizeof(char *) * k);
    *returnSize = k;
    
    for(i = 0; i < count; ++i){
        top = -1;
        temp = nums[digits[i] - '0'];
        len = strlen(temp);
        k /= num[i];
        for(h = 0; h < s; ++h){
            for(t = 0; t < len; ++t){
                for(j = 0; j < k; ++j){
                    if(0 == i){
                        str[++top] = (char *)malloc(sizeof(char) * count);
                        str[top][i] = temp[t];
                    }
                    else
                        str[++top][i] = temp[t];
                }
            }
        }
        s *= num[i];
    }
    
    return str;
    

    }
    '''


Log in to reply
 

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