Write a function that takes a string as input and returns the string reversed.
Example:
Given s = "hello", return "olleh".
A:Given s = "hello", return "olleh".
class Solution { public: void reverseString(vector<char>& s) { int i =0, j = s.size()-1; while(i<j){ swap(s[i],s[j]); ++i; --j; } } };
No comments:
Post a Comment