344. Reverse String (转置字符串)

古城微笑少年丶 2022-07-15 01:37 185阅读 0赞

Write a function that takes a string as input and returns the string reversed.

Example:

Given s = “hello”, return “olleh”.

  1. public class Solution {
  2. public String reverseString(String s) {
  3. StringBuilder sb = new StringBuilder();
  4. for(int i=s.length()-1;i>=0;i--){
  5. sb.append(s.charAt(i));
  6. }
  7. return sb.toString();
  8. }
  9. }

发表评论

表情:
评论列表 (有 0 条评论,185人围观)

还没有评论,来说两句吧...

相关阅读

    相关 字符串----344. 反字符串

    / 344. 反转字符串 编写一个函数,其作用是将输入的字符串反转过来。输入字符串以字符数组 char[] 的形式给出。 不要给另外的数组分配额外的空间,你必须原