题解 | #反转字符串#
反转字符串
http://www.nowcoder.com/practice/c3a6afee325e472386a1c4eb1ef987f3
记录
import java.util.*;
public class Solution {
/**
* 反转字符串
* @param str string字符串
* @return string字符串
*/
public String solve (String str) {
// write code here
if (str == null || str.length() <= 1){
return str;
}
char[] chars = str.toCharArray();
int len = chars.length;
for (int i = 0; i < len / 2; i++){
char temp = chars[i];
chars[i] = chars[len - i - 1];
chars[len - i - 1] = temp;
}
return new String(chars);
}
}
