344. reverse string

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

Example:
Given s = “hello”, return “olleh”.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Solution {
public:
string (string s) {
string str = s;
int i = 0;
int j = str.size() - 1;
for (; i < j; i++,j--) {
char c = str[i];
str[i] = str[j];
str[j] = c;
}
return str;
}
};