344. Reverse String(C++)

来源:互联网 发布:鬼武者 知乎 编辑:程序博客网 时间:2024/05/21 09:34

题目:

Write a function that takes a string as input and returns the string reversed.
造一个方法让输入的的字符串反转(这个不用谷歌我也可以翻译hh)
Example:
Given s = “hello”, return “olleh”.

直接贴代码:

class Solution {public:    string reverseString(string s) {        int i=0,j=s.size()-1;        while(i<j)        {            swap(s[i],s[j]);            i++;            j--;        }        return s;    }};
0 0