导航

LeetCode 344. Reverse String

Posted on 2016-09-20 21:58  CSU蛋李  阅读(84)  评论(0编辑  收藏  举报

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) {
        char temp=' ';
        for(int i=0;i<s.size()/2;++i)
        {
            temp=s[i];
            s[i]=s[s.size()-1-i];
            s[s.size()-1-i]=temp;
        }
        return s;
    }
};