首页 > 代码库 > 反转字符串

反转字符串

Write a function that takes a string as input and returns the string reversed.

Example:
Given s = "hello", return "olleh".

char* reverseString(char* s) {    int len = strlen(s);    for (int i=0; i<len/2; i++) {        char t = s[i];        s[i] = s[len-i-1];        s[len-i-1] = t;    }    return s;}

 

反转字符串