1844. Replace All Digits with Characters Easy

@problem@discussion
#String



1/**
2 * [1844] Replace All Digits with Characters
3 *
4 * You are given a 0-indexed string s that has lowercase English letters in its even indices and digits in its odd indices.
5 * There is a function shift(c, x), where c is a character and x is a digit, that returns the x^th character after c.
6 * 
7 * 	For example, shift('a', 5) = 'f' and shift('x', 0) = 'x'.
8 * 
9 * For every odd index i, you want to replace the digit s[i] with shift(s[i-1], s[i]).
10 * Return s after replacing all digits. It is guaranteed that shift(s[i-1], s[i]) will never exceed 'z'.
11 *  
12 * Example 1:
13 * 
14 * Input: s = "a1c1e1"
15 * Output: "abcdef"
16 * Explanation: The digits are replaced as follows:
17 * - s[1] -> shift('a',1) = 'b'
18 * - s[3] -> shift('c',1) = 'd'
19 * - s[5] -> shift('e',1) = 'f'
20 * Example 2:
21 * 
22 * Input: s = "a1b2c3d4e"
23 * Output: "abbdcfdhe"
24 * Explanation: The digits are replaced as follows:
25 * - s[1] -> shift('a',1) = 'b'
26 * - s[3] -> shift('b',2) = 'd'
27 * - s[5] -> shift('c',3) = 'f'
28 * - s[7] -> shift('d',4) = 'h'
29 *  
30 * Constraints:
31 * 
32 * 	1 <= s.length <= 100
33 * 	s consists only of lowercase English letters and digits.
34 * 	shift(s[i-1], s[i]) <= 'z' for all odd indices i.
35 * 
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/replace-all-digits-with-characters/
40// discuss: https://leetcode.com/problems/replace-all-digits-with-characters/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45    pub fn replace_digits(s: String) -> String {
46        String::new()
47    }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55
56    #[test]
57    fn test_1844() {
58    }
59}
60


Back
© 2025 bowen.ge All Rights Reserved.