Write a function that takes a string as input and returns the string reversed.
Example:
Given s = "hello", return "olleh".
一刷
题解:two pointer
public class Solution {
public String reverseString(String s) {
char[] chs = s.toCharArray();
int l = 0, r = s.length()-1;
while(l<r){
char temp = chs[l];
chs[l] = chs[r];
chs[r] = temp;
l++;
r--;
}
return new String(chs);
}
}