848. Shifting Letters

1
2
3
4
5
6
7
8
9
10
11
class Solution {
public String shiftingLetters(String s, int[] shifts) {
int shiftCount = 0;
char[] chars = s.toCharArray();
for (int i = chars.length - 1; i >= 0; i--) {
shiftCount += shifts[i] % 26;
chars[i] = (char) ('a' + (chars[i] - 'a' + shiftCount) % 26);
}
return new String(chars);
}
}

References

848. Shifting Letters