good,练习chunk的使用。
(s: String, k: i32)
| 1 | // good,练习chunk的使用。 |
| 2 | pub fn reverse_str(s: String, k: i32) -> String { |
| 3 | let mut ret_c = s.chars().collect::<Vec<char>>(); |
| 4 | let mut idx = 0; |
| 5 | for chunk in ret_c.chunks_mut(k as usize) { |
| 6 | if idx % 2 == 0 { |
| 7 | let mut tmp = chunk.to_vec(); |
| 8 | tmp.reverse(); |
| 9 | for (i, elem) in chunk.iter_mut().enumerate() { |
| 10 | *elem = tmp[i]; |
| 11 | } |
| 12 | } |
| 13 | idx += 1; |
| 14 | } |
| 15 | ret_c.iter().collect() |
| 16 | } |
| 17 | |
| 18 | fn main() { |
| 19 | let s = "abcd".to_string(); |
nothing calls this directly
no outgoing calls
no test coverage detected