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

Function reverse_prefix

2000-reverse-prefix-of-word.rs:18–30  ·  view source on GitHub ↗
(word: String, ch: char)

Source from the content-addressed store, hash-verified

16}
17
18pub fn reverse_prefix(word: String, ch: char) -> String {
19 let s_index = word.find(ch);
20 match s_index {
21 Some(p) => {
22 let res = word.clone();
23 let mut left = res[..p+1].chars().rev().collect::<String>();
24 let right: String = res[p+1..].to_string();
25 left.push_str(&right);
26 left
27 },
28 None => word,
29 }
30}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected