问题描述:Write a function that takes a string as input and returns the string reversed
Example:
Given s = "hello", return "olleh".
此题很简单,使用java StringBuffer下reverse命令即可
最简单的方法:
public class Solution
{
public String reverseString(String s)
{
return new StringBuffer(s).reverse().toString();
}
}
即:
public class Solution
{
public String reverseString(String s)
{
StringBuffer b = new StringBuffer(s);
return b.reverse().toString();
}
}
StringBuffer(String str)
Constructs a string buffer initialized to the contents of the specified string.
reverse()
Causes this character sequence to be replaced by the reverse of the sequence.
toString()
This object (which is already a string!) is itself returned.