原题网址:https://leetcode.com/problems/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) {
if (s == null) return null;
char[] sa = s.toCharArray();
char[] r = new char[sa.length];
for(int i=0; i<sa.length; i++) r[i] = sa[sa.length-1-i];
return new String(r);
}
}