Reverse String
Total Accepted: 32384
Total Submissions: 55169
Difficulty: Easy
Write a function that takes a string as input and returns the string reversed.
Example:
Given s = "hello", return "olleh".
Subscribe to see which companies asked this question
Hide Similar Problems
c++ code:
class Solution {
public:
string reverseString(string s) {
int len = s.length();
int i=0,j=len-1;
while(i<j) {
s[i] ^= s[j] ^= s[i] ^= s[j];
i++;
j--;
}
return s;
}
};