我是菜鸟,我暂时没有考虑效率的问题,直接就为达目的不择手段了,能解决对我来说已经很不错了,等我经验多一点了,再考虑更多一些,请大家多多包涵,多多指正!
import java.util.*; import java.lang.StringBuffer; public class Solution { public String LeftRotateString(String str,int n) { String string = ""; StringBuilder stringB = new StringBuilder(str); char c[] = str.toCharArray(); if(c == null || c.length == 0){ return ""; } for(int i = 0; i < n; i++){ //deleteCharAt() 定位删除 stringB.deleteCharAt(0); stringB.append(c[i]); } string = stringB.toString(); return string; } }