Share my solution in pure C


  • 0
    J
    char** generatePossibleNextMoves(char* s, int* returnSize) {
        char** p = (char**)malloc(10000 * sizeof(char*));
        int len = 0;
        for (int i = 0; s[i] != '\0'; i++, len++);
        int idx = 0;
        for (int i = 1; s[i] != '\0'; i++) {
            if (s[i - 1] == '+' && s[i] == '+') {
                p[idx] = (char*)malloc(len + 1);
                memcpy(p[idx], s, len + 1);
                p[idx][i - 1] = p[idx][i] = '-';
                idx++;
            }
        }
        *returnSize = idx;
        return p;
    }

Log in to reply
 

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