// 左闭右开
fn reverse(s: &mut String, i: usize, j: usize) {
let mut p = unsafe { s.as_bytes_mut() };
let mut j = j - 1;
let mut i = i;
while i < j {
p.swap(i, j);
i += 1;
j -= 1;
}
}
//左移
fn left_rotate(s: &mut String, k: usize) {
reverse(&mut s, 0, s.len());
reverse(&mut s, 0, s.len() - k);
reverse(&mut s, s.len() - k, s.len());
}
//左移
fn right_rotate(s: &mut String, k: usize) {
reverse(&mut s, 0, s.len());
reverse(&mut s, 0, k);
reverse(&mut s, k, s.len());
}
标签:右移,mut,reverse,模版,len,let,usize,fn
From: https://www.cnblogs.com/wyzwsy/p/18227552