import java.util.*;
public class Solution {
/**
* 反转字符串
* @param str string字符串
* @return string字符串
*/
//时间复杂度O(n),空间复杂度O(n)
public String solve (String str) {
// write code here
char[] c = new char[str.length()];
int j=0;
for(int i=str.length()-1;i>=0;i--){
c[j] = str.charAt(i);
j++;
}
return new String(c); //字符转换为字符串
}
}
//想要在原地交换,就要将字符串转换为字符数组
//时间复杂度O(n),空间复杂度O(1)
import java.util.*;
public class Solution {
public String solve (String str) {
char[] cstr = str.toCharArray();
int len = str.length();
for(int i = 0 ; i < len/2 ;i++)
{
char t = cstr[i];
cstr[i] = cstr[len-1-i];
cstr[len-1-i]=t;
}
return new String(cstr);
}
}