344. Reverse String

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

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

class Solution {
public:
    string reverseString(string s) {
        if(s.size()==0)
            return s;
        int start = 0;
        int end = s.size()-1;
        while(start<end){
            char tmp ;
            tmp = s[start];
            s[start] = s[end];
            s[end ] = tmp;
            start++;
            end--;
        }
        return s;
    }
};

 

posted on 2017-03-05 08:17  123_123  阅读(53)  评论(0编辑  收藏  举报