Reverse String

2017-03-14  本文已影响0人  burglar

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;
}
上一篇下一篇

猜你喜欢

热点阅读