1
2
3
4
5
6
7
8
9
10
11
12
13
| // @Title: 反转单词前缀 (Reverse Prefix of Word)
// @Author: 15816537946@163.com
// @Date: 2022-02-02 22:20:34
// @Runtime: 0 ms
// @Memory: 1.9 MB
impl Solution {
pub fn reverse_prefix(word: String, ch: char) -> String {
if let Some(i) = word.find(ch) {
return [&word[..=i].chars().rev().collect::<String>(), &word[i+1..]].concat();
}
word
}
}
|