LeetCode:344. Reverse String

来源:互联网 发布:importnew java 编辑:程序博客网 时间:2024/06/14 09:32

Write a function that takes a string as input and returns the string reversed.

Example:
Given s = "hello", return "olleh".

AC:

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

0 0