题目:
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 [] buffer = s.toCharArray();
int begin = 0;
int end = buffer.length - 1;
char temp;
while(end > begin){
temp = buffer[begin];
buffer[begin] = buffer[end];
buffer[end] = temp;
end--;
begin++;
}
return new String(buffer);
}
}