question
Write a function that takes a string as input and returns the string reversed.
Example:
Given s = "hello", return "olleh".
solution
char* reverseString(char* s){
int size;
for(size=0;s[size]!='\0';size++);
int low=0,high=size-1;
char tmp;
while(low<high){
tmp=s[low];
s[low]=s[high];
s[high]=tmp;
low++;
high--;
}
return s;
}
网友评论