Class Solution

java.lang.Object
g0801_0900.s0848_shifting_letters.Solution

public class Solution extends Object
848 - Shifting Letters.<p>Medium</p> <p>You are given a string <code>s</code> of lowercase English letters and an integer array <code>shifts</code> of the same length.</p> <p>Call the <code>shift()</code> of a letter, the next letter in the alphabet, (wrapping around so that <code>'z'</code> becomes <code>'a'</code>).</p> <ul> <li>For example, <code>shift('a') = 'b'</code>, <code>shift('t') = 'u'</code>, and <code>shift('z') = 'a'</code>.</li> </ul> <p>Now for each <code>shifts[i] = x</code>, we want to shift the first <code>i + 1</code> letters of <code>s</code>, <code>x</code> times.</p> <p>Return <em>the final string after all such shifts to s are applied</em>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;abc&rdquo;, shifts = [3,5,9]</p> <p><strong>Output:</strong> &ldquo;rpl&rdquo;</p> <p><strong>Explanation:</strong> We start with &ldquo;abc&rdquo;.</p> <p>After shifting the first 1 letters of s by 3, we have &ldquo;dbc&rdquo;.</p> <p>After shifting the first 2 letters of s by 5, we have &ldquo;igc&rdquo;.</p> <p>After shifting the first 3 letters of s by 9, we have &ldquo;rpl&rdquo;, the answer.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;aaa&rdquo;, shifts = [1,2,3]</p> <p><strong>Output:</strong> &ldquo;gfd&rdquo;</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s.length <= 10<sup>5</sup></code></li> <li><code>s</code> consists of lowercase English letters.</li> <li><code>shifts.length == s.length</code></li> <li><code>0 <= shifts[i] <= 10<sup>9</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • shiftingLetters

      public String shiftingLetters(String s, int[] shifts)