c 4ms solution


  • 0
    W
    char* reverseString(char* s) {
        char * result = malloc((strlen(s)+1)*sizeof(char));
        memset(result,'\0',(strlen(s)+1)*sizeof(char));
        result += strlen(s)-1;
        while(*s != '\0'){
            *(result--) = *(s++);
        }
        result +=1;
        return result;
    }

Log in to reply
 

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