image

编辑人: 未来可期

calendar2025-06-07

message1

visits145

翻手算法 如现在有一串字符:ABCDEFG,让前两个字符循环左移到整个个字符串的右边,结果即:CDEFGAB

public class FanShou {
public static void main(String[] args) {
String str = “ABCDEFG”;
String result = new FanShou().process(str, 3);
System.out.println(result);
}
public String process(String str, int m){
char[] cs = str.toCharArray();
turnHand(cs,0,m-1);//前半部分转置
turnHand(cs,m,cs.length-1);//后半部分转置
turnHand(cs,0,cs.length-1);//所有字符串转置
return new String(cs);
}
public void turnHand(char[] cs,int i,int j){
int length = j-i+1;
for(int t=0;t

喵呜刷题:让学习像火箭一样快速,快来微信扫码,体验免费刷题服务,开启你的学习加速器!

创作类型:
原创

本文链接:翻手算法 如现在有一串字符:ABCDEFG,让前两个字符循环左移到整个个字符串的右边,结果即:CDEFGAB

版权声明:本站点所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明文章出处。
分享文章
share