848. Shifting Letters Medium

@problem@discussion
#Array#String



1/**
2 * [848] Shifting Letters
3 *
4 * You are given a string s of lowercase English letters and an integer array shifts of the same length.
5 * Call the shift() of a letter, the next letter in the alphabet, (wrapping around so that 'z' becomes 'a').
6 * 
7 * 	For example, shift('a') = 'b', shift('t') = 'u', and shift('z') = 'a'.
8 * 
9 * Now for each shifts[i] = x, we want to shift the first i + 1 letters of s, x times.
10 * Return the final string after all such shifts to s are applied.
11 *  
12 * Example 1:
13 * 
14 * Input: s = "abc", shifts = [3,5,9]
15 * Output: "rpl"
16 * Explanation: We start with "abc".
17 * After shifting the first 1 letters of s by 3, we have "dbc".
18 * After shifting the first 2 letters of s by 5, we have "igc".
19 * After shifting the first 3 letters of s by 9, we have "rpl", the answer.
20 * 
21 * Example 2:
22 * 
23 * Input: s = "aaa", shifts = [1,2,3]
24 * Output: "gfd"
25 * 
26 *  
27 * Constraints:
28 * 
29 * 	1 <= s.length <= 10^5
30 * 	s consists of lowercase English letters.
31 * 	shifts.length == s.length
32 * 	0 <= shifts[i] <= 10^9
33 * 
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/shifting-letters/
38// discuss: https://leetcode.com/problems/shifting-letters/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43    pub fn shifting_letters(s: String, shifts: Vec<i32>) -> String {
44        String::new()
45    }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52    use super::*;
53
54    #[test]
55    fn test_848() {
56    }
57}
58


Back
© 2025 bowen.ge All Rights Reserved.