Reverse String
Write a function that takes a string as input and returns the string reversed.
Example:
Given s = “hello”, return “olleh”.
public class Solution {
public String reverseString(String s) {
char[] str = s.toCharArray();
int start = 0;
int end = str.length - 1;
while (start < end) {
char temp = str[start];
str[start] = str[end];
str[end] = temp;
start++;
end--;
}
return new String(str);
}
}