LeetCode 344. Reverse String

时间:2022-01-10 20:50:27

Problem:

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

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

此题一般思路为:在原数组上直接对s[i]以及s[len-i-1]进行调换即可。

 char* reverseString(char* s) {
int i = , len = ;
len = strlen(s);
for (i = ; i < len / ; i++) {
int tmp = s[i];
s[i] = s[len - i - ];
s[len - i - ] = tmp;
}
return s;
}