Leetcode题目:Reverse String

题目:

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

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

解答:这个题目超级无敌简单,就是把一个string给逆过来输出。

代码:

class Solution {
public:
    string reverseString(string s) {
        stringstream res;
        res.clear();
        for(int i = s.length() - 1;i >= 0;i--)
        {
            res << s[i];
        }
        return res.str();
    }
};

posted @ 2016-04-22 16:48  CodingGirl121  阅读(106)  评论(0编辑  收藏  举报