344. Reverse String

来源:互联网 发布:信息 互联网 大数据 编辑:程序博客网 时间:2024/06/05 09:33

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 j = s.size()-1, i = 0;        while(i < j)        {        swap(s[i++], s[j--]);        }                return s;            }};


0 0
原创粉丝点击