344 - Reverse String
#easy
Write a function that reverses a string. The input string is given as an array of characters s.
You must do this by modifying the input array in-place with O(1) extra memory.
Example 1:
Input: s = ["h","e","l","l","o"]
Output: ["o","l","l","e","h"]
class Solution {
public:
void reverseString(vector<char>& s) {
int i = 0;
int j = s.size() - 1;
while ( i < j ) {
swap(s[i],s[j]);
i++;
j--;
}
}
void reverseString(char* s, int sSize){
char * start = s;
for ( int i = 0; sSize / 2 > i; i++ ) {
char temp = s[i];
s[i] = s[sSize-1-i];
s[sSize-1-i] = temp;
}
return start;
}