344.Reverse String

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

class Solution {
public:
    string reverseString(string s) {
        int start =0, end = s.size() - 1;

        while(start < end){
            swap(s[start++], s[end--]);
        }
        return s;
    }
};

results matching ""

    No results matching ""