leetcode 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 ans="";
        int n=s.length();
        for(int i=n-1;i>=0;i--){
            ans+=s[i];
        }
        return ans;
    }
};

 

posted @ 2016-04-23 02:04  周洋  阅读(149)  评论(0编辑  收藏  举报