3794. Reverse String Prefix Easy
1/**
2 * [3794] Reverse String Prefix
3 *
4 * You are given a string s and an integer k.
5 * Reverse the first k characters of s and return the resulting string.
6 *
7 * <strong class="example">Example 1:
8 * <div class="example-block">
9 * Input: <span class="example-io">s = "abcd", k = 2</span>
10 * Output: <span class="example-io">"bacd"</span>
11 * Explanation:
12 * The first k = 2 characters "ab" are reversed to "ba". The final resulting string is "bacd".
13 * </div>
14 * <strong class="example">Example 2:
15 * <div class="example-block">
16 * Input: <span class="example-io">s = "xyz", k = 3</span>
17 * Output: <span class="example-io">"zyx"</span>
18 * Explanation:
19 * The first k = 3 characters "xyz" are reversed to "zyx". The final resulting string is "zyx".
20 * </div>
21 * <strong class="example">Example 3:
22 * <div class="example-block">
23 * Input: <span class="example-io">s = "hey", k = 1</span>
24 * Output: <span class="example-io">"hey"</span>
25 * Explanation:
26 * The first k = 1 character "h" remains unchanged on reversal. The final resulting string is "hey".
27 * </div>
28 *
29 * Constraints:
30 *
31 * 1 <= s.length <= 100
32 * s consists of lowercase English letters.
33 * 1 <= k <= s.length
34 *
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/reverse-string-prefix/
39// discuss: https://leetcode.com/problems/reverse-string-prefix/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44 pub fn reverse_prefix(s: String, k: i32) -> String {
45 String::new()
46 }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn test_3794() {
57 }
58}
59Back
© 2026 bowen.ge All Rights Reserved.