https://leetcode.com/problems/reverse-string/
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) {
int len = s.length();
char[] c = new char[len];
for(int i = 0; i<s.length(); i++){
c[len-i-1] = s.charAt(i);
}
return new String(c);
}
}
本文介绍了一个简单的字符串反转函数实现过程,通过循环遍历输入字符串并将其字符逆序存入新数组,最后转换为字符串返回。
542

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



