题解 | #反转字符串#
反转字符串
http://www.nowcoder.com/practice/c3a6afee325e472386a1c4eb1ef987f3
遍历
倒序遍历,从后往前遍历即可
import java.util.*;
public class Solution {
/**
* 反转字符串
* @param str string字符串
* @return string字符串
*/
public String solve (String str) {
int n = str.length();
char strs[] = new char[n];
for(int i = n - 1;i >= 0;i--){
strs[i] = str.charAt(n - 1 - i);
}
return new String(strs);
}
}
查看12道真题和解析