【leetcode | KamaCoder 25】55.右旋字符串(第八期模拟笔试)
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner in=new Scanner(System.in);
int n=Integer.parseInt(in.nextLine());
String s=in.nextLine();
int len=s.length();
char[] chars=s.toCharArray();
reverseString(chars,0,len-1);
reverseString(chars,0,n-1);
reverseString(chars,n,len-1);
System.out.println(chars);
}
public static void reverseString(char[] ch,int start,int end){
while(start<end){
ch[start]^=ch[end];
ch[end]^=ch[start];
ch[start]^=ch[end];
start++;
end--;
}
}
}
原文地址:https://blog.csdn.net/weixin_45780075/article/details/145283479
免责声明:本站文章内容转载自网络资源,如侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!