344. Reverse String

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

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

反转字符串,逼我不用 reverse

class Solution {
public:
    string reverseString(string s) {
        int n = s.length();
        int l = 0, r = n - 1;
        while(l < r) {
            swap(s[l++],s[r--]);
        }
        return s;
    }
};
原文地址:https://www.cnblogs.com/pk28/p/7247632.html