【字符串】848. 字母移位

题目:

 

 

解答:

 1 class Solution {
 2 public:
 3     string shiftingLetters(string S, vector<int>& shifts) 
 4     {
 5         int size = (int)S.size();
 6         int cnt = 0;
 7         for (int i = size - 1; i >= 0;i--) 
 8         {
 9             cnt += shifts[i] % 26;
10             int index = S[i] - 'a' + cnt;
11             S[i] = (index % 26) + 'a';
12         }
13         return S;
14     }
15 };

 

posted @ 2020-05-04 12:52  梦醒潇湘  阅读(223)  评论(0)    收藏  举报