请编写一个函数,其功能是将输入的字符串反转过来。
示例:
输入:s = "hello" 返回:"olleh"
class Solution {
public String reverseString(String s) {
char[] chars = s.toCharArray();
int i = 0;
int j = chars.length - 1;
while (i < j) {
char temp = chars[i];
chars[i] = chars[j];
chars[j] = temp;
i++;
j--;
}
return new String(chars);
}
}