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) {
StringBuilder sb=new StringBuilder();
for(int i=s.length()-1;i>=0;i--){
sb.append(s.charAt(i));
}
return sb.toString();
}
}
本文介绍了一个将字符串反转的简单函数实现,并通过实例演示了其使用方法。
2192

被折叠的 条评论
为什么被折叠?



