You are given a character array s. Reverse the array in-place, meaning you must do it without allocating extra space for another array.
Example 1
Example 2
Edge Cases to Consider
Solution:
public void reverseString(char[] s) {
int start = 0, end = s.length - 1;
while(start < end) {
char t = s[start];
s[start++] = s[end];
s[end--] = t;
}
}
/** API to support String input to reverse.**/
public static String reverse(String s) {
char[] t = s.toCharArray();
reverse(t);
return new String(t);
}