美文网首页
Reverse String

Reverse String

作者: burglar | 来源:发表于2017-03-14 15:07 被阅读0次

    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;
    }
    

    相关文章

      网友评论

          本文标题:Reverse String

          本文链接:https://www.haomeiwen.com/subject/ddhhnttx.html