题意:给出一个字符串,将其反转
代码如下:
public class Solution
{
public String reverseString(String s)
{
StringBuilder sb = new StringBuilder(s);
int left = 0, right = sb.length() - 1;
while (left < right)
{
char ch = sb.charAt(left);
sb.setCharAt(left, sb.charAt(right));
sb.setCharAt(right, ch);
left++;
right--;
}
return sb.toString();
}
}