Reverse String (C)


  • 0
    P
    //Here provide a simple C solution:
    char* reverseString(char* s) {
        int i, StrLen = strlen(s); //String Length
        char *pNewStr = malloc(StrLen * sizeof(int));
        for ( i = 0; i < StrLen; i++ ){
            *(pNewStr+i) = *(s+StrLen-i-1);
        }
        *(pNewStr+StrLen) = '\0';
        return pNewStr;
    }

Log in to reply
 

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