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) {
        string result;
        int len = s.size();
        if(len==0) return result;
        int i = 0, j = len-1;
        while(i < len)
        {
            result += s[j];
            i++;
            j--;
        }
        return result;
    }
};


你可能感兴趣的:(344. Reverse String)