LeetCode: 344. 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[] arrays = s.toCharArray();
int length = arrays.length;
int half = length >> 1;
for (int i = 0; i < half; i++) {
char temp = arrays[i];
arrays[i] = arrays[length - 1 - i];
arrays[length - 1 - i] = temp;
}
return new String(arrays);
}
}