Leetcode 878 Solution

This article provides solution to leetcode question 878 (shifting-letters)

https://leetcode.com/problems/shifting-letters

Solution

class Solution {
public:
    string shiftingLetters(string S, vector<int>& shifts) {
        int s = 0;
        for (int i = shifts.size() - 1; i >= 0; i--)
        {
            s += shifts[i] % 26;
            shifts[i] = s;
        }

        for (int i = 0; i < S.size(); i++)
        {
            int ch = S[i] - 'a';
            ch = (ch + shifts[i]) % 26;
            S[i] = ch + 'a';
        }

        return S;
    }
};