示例 1:
输入:["h","e","l","l","o"]
输出:["o","l","l","e","h"]
示例 2:
输入:["H","a","n","n","a","h"]
输出:["h","a","n","n","a","H"]
java实现:
public static String reverseString(String s) {
if (s == null){
return null;
}
char[] charts = s.toCharArray();
StringBuilder sb = new StringBuilder();
int len = charts.length;
for (int i = len-1; i >= 0; i--) {
sb.append(charts[i]);
}
return sb.toString();
}
public static void main(String[] args){
String s="hello";
reverseString(s);
}