题意:

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

Example:
Given s = "hello", return "olleh".

就是将一个字符串翻转输出。

 public String reverseString(String s) {
        if(s == null || s.length() < 2)
            return s;
        char[] chars = s.toCharArray();
        for(int i=0; i<chars.length / 2; i++){
            char temp = chars[chars.length - 1 - i];
            chars[chars.length - 1 - i] = chars[i];
            chars[i] = temp;
        }
        return new String(chars);
    }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-06
  • 2021-04-24
  • 2022-02-12
猜你喜欢
  • 2021-07-04
  • 2021-06-24
  • 2021-12-12
  • 2021-10-03
相关资源
相似解决方案