Write a function that takes a string as input and returns the string reversed.
Example:
Given s = "hello", return "olleh".
Subscribe to see which companies asked this question.
简单题 不赘述 两行代码
public String reverseString(String s) {
StringBuffer s1=new StringBuffer(s);
return s1.reverse().toString();
}
自己写也可以
StringBuffer s1=new StringBuffer();
for(int i=s.length()-1;i>=0;i--){
s1=s1.append(s.charAt(i)) ;
}
return s1.toString();