3823. Reverse Letters Then Special Characters in a String Easy

@problem@discussion
#Two Pointers#String#Simulation



1/**
2 * [3823] Reverse Letters Then Special Characters in a String
3 *
4 * You are given a string s consisting of lowercase English letters and special characters.
5 * Your task is to perform these in order:
6 * 
7 * 	Reverse the lowercase letters and place them back into the positions originally occupied by letters.
8 * 	Reverse the special characters and place them back into the positions originally occupied by special characters.
9 * 
10 * Return the resulting string after performing the reversals.
11 *  
12 * <strong class="example">Example 1:
13 * <div class="example-block">
14 * Input: <span class="example-io">s = "</span>)ebc#da@f(<span class="example-io">"</span>
15 * Output: <span class="example-io">"</span>(fad@cb#e)<span class="example-io">"</span>
16 * Explanation:
17 * 
18 * 	The letters in the string are ['e', 'b', 'c', 'd', 'a', 'f']:
19 * 	
20 * 		Reversing them gives ['f', 'a', 'd', 'c', 'b', 'e']
21 * 		s becomes ")fad#cb@e("
22 * 	
23 * 	
24 * 	​​​​​​​The special characters in the string are [')', '#', '@', '(']:
25 * 	
26 * 		Reversing them gives ['(', '@', '#', ')']
27 * 		s becomes <span class="example-io">"</span>(fad@cb#e)<span class="example-io">"</span>
28 * 	
29 * 	
30 * </div>
31 * <strong class="example">Example 2:
32 * <div class="example-block">
33 * Input: <span class="example-io">s = "z"</span>
34 * Output: <span class="example-io">"z"</span>
35 * Explanation:
36 * The string contains only one letter, and reversing it does not change the string. There are no special characters.
37 * </div>
38 * <strong class="example">Example 3:
39 * <div class="example-block">
40 * Input: <span class="example-io">s = "!@#$%^&amp;*()"</span>
41 * Output: <span class="example-io">"</span>)(*&amp;^%$#@!<span class="example-io">"</span>
42 * Explanation:
43 * The string contains no letters. The string contains all special characters, so reversing the special characters reverses the whole string.
44 * </div>
45 *  
46 * Constraints:
47 * 
48 * 	1 <= s.length <= 100
49 * 	s consists only of lowercase English letters and the special characters in "!@#$%^&amp;*()".
50 * 
51 */
52pub struct Solution {}
53
54// problem: https://leetcode.com/problems/reverse-letters-then-special-characters-in-a-string/
55// discuss: https://leetcode.com/problems/reverse-letters-then-special-characters-in-a-string/discuss/?currentPage=1&orderBy=most_votes&query=
56
57// submission codes start here
58
59impl Solution {
60    pub fn reverse_by_type(s: String) -> String {
61        String::new()
62    }
63}
64
65// submission codes end
66
67#[cfg(test)]
68mod tests {
69    use super::*;
70
71    #[test]
72    fn test_3823() {
73    }
74}
75

Back
© 2026 bowen.ge All Rights Reserved.