c solution 3ms


  • 2
    T

    char* reverseString(char* s) {

      int i , j , n;
      n = strlen(s);
      char* tmp = (char*)malloc(sizeof(char)*(n+1));
    
      for(i=n,j=0;i>0;i--,j++)
          tmp[j] = s[i-1];
          
      tmp[n] = '\0';
      
      return tmp ;
    

    }


  • 0
    H

    The tmp pointer doesn't destroy after the function returns.
    Will it be okay?


Log in to reply
 

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