解一,双指针翻转
pub fn reverse_string(s: &mut Vec<char>) {
let mut left = 0usize;
let mut right = s.len() - 1;
while left < right {
s.swap(left, right);
left += 1;
right -= 1;
}
}
时间: 空间:
pub fn reverse_string(s: &mut Vec<char>) {
let mut left = 0usize;
let mut right = s.len() - 1;
while left < right {
s.swap(left, right);
left += 1;
right -= 1;
}
}
时间: 空间: