2000. Reverse Prefix of Word Easy
1/**
2 * [2000] Reverse Prefix of Word
3 *
4 * Given a 0-indexed string word and a character ch, reverse the segment of word that starts at index 0 and ends at the index of the first occurrence of ch (inclusive). If the character ch does not exist in word, do nothing.
5 *
6 * For example, if word = "abcdefd" and ch = "d", then you should reverse the segment that starts at 0 and ends at 3 (inclusive). The resulting string will be "<u>dcba</u>efd".
7 *
8 * Return the resulting string.
9 *
10 * Example 1:
11 *
12 * Input: word = "<u>abcd</u>efd", ch = "d"
13 * Output: "<u>dcba</u>efd"
14 * Explanation: The first occurrence of "d" is at index 3.
15 * Reverse the part of word from 0 to 3 (inclusive), the resulting string is "dcbaefd".
16 *
17 * Example 2:
18 *
19 * Input: word = "<u>xyxz</u>xe", ch = "z"
20 * Output: "<u>zxyx</u>xe"
21 * Explanation: The first and only occurrence of "z" is at index 3.
22 * Reverse the part of word from 0 to 3 (inclusive), the resulting string is "zxyxxe".
23 *
24 * Example 3:
25 *
26 * Input: word = "abcd", ch = "z"
27 * Output: "abcd"
28 * Explanation: "z" does not exist in word.
29 * You should not do any reverse operation, the resulting string is "abcd".
30 *
31 *
32 * Constraints:
33 *
34 * 1 <= word.length <= 250
35 * word consists of lowercase English letters.
36 * ch is a lowercase English letter.
37 *
38 */
39pub struct Solution {}
40
41// problem: https://leetcode.com/problems/reverse-prefix-of-word/
42// discuss: https://leetcode.com/problems/reverse-prefix-of-word/discuss/?currentPage=1&orderBy=most_votes&query=
43
44// submission codes start here
45
46impl Solution {
47 pub fn reverse_prefix(word: String, ch: char) -> String {
48 String::new()
49 }
50}
51
52// submission codes end
53
54#[cfg(test)]
55mod tests {
56 use super::*;
57
58 #[test]
59 fn test_2000() {
60 }
61}
62
Back
© 2025 bowen.ge All Rights Reserved.