解法一:
public class Solution {
public String reverseStr(String s, int k) {
StringBuilder sb = new StringBuilder();
for(int i = 0; i < s.length(); i += 2*k){
int leftlength = s.length() - i;//leftlength代表当前剩下的字符串的长度
if(leftlength < k){
sb.append(new StringBuilder(s.substring(i, i + leftlength)).reverse().toString());
} else if(leftlength < 2*k){
sb.append(new StringBuilder(s.substring(i, i + k)).reverse().append(s.substring(i + k)).toString());
} else{
sb.append(new StringBuilder(s.substring(i, i + k)).reverse().append(s.substring(i + k, i + k + k)).toString());
}
}
return sb.toString();
}
}