MCPcopy Create free account
hub / github.com/StudyRust/leetcode_rust / reverse_only_letters

Function reverse_only_letters

917-reverse-only-letters.rs:1–20  ·  view source on GitHub ↗
(s: String)

Source from the content-addressed store, hash-verified

1pub fn reverse_only_letters(s: String) -> String {
2 let mut idxs: Vec<usize> = vec!();
3 let mut tmp = String::new();
4 for (i, c) in s.chars().enumerate() {
5 if c.is_alphabetic() {
6 idxs.push(i);
7 tmp.push(c);
8 }
9 }
10 let mut s = s;
11 unsafe {
12 let vec = s.as_mut_vec();
13 let tmp_vec = tmp.as_mut_vec();
14 tmp_vec.reverse();
15 for (i, c) in tmp_vec.iter().enumerate() {
16 vec[idxs[i]] = *c;
17 }
18 }
19 s
20}
21
22fn main() {
23 let s = "Test1ng-Leet=code-Q!".to_string();

Callers

nothing calls this directly

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected