- 翻转前n个字符
- 翻转其余字符
- 翻转所有字符
class Solution {
public String reverseLeftWords(String s, int n) {
char[] ch = s.toCharArray();
reverse(ch, 0, n - 1);
reverse(ch, n, ch.length - 1);
reverse(ch, 0, ch.length - 1);
return new String(ch);
}
void reverse(char[] ch, int l, int r){
while(l < r){
char tmp = ch[l];
ch[l] = ch[r];
ch[r] = tmp;
l++;
r--;
}
}
}