344. Reverse String

来源:互联网 发布:淘宝买ps3 编辑:程序博客网 时间:2024/05/29 09:57

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