-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path2381.cpp
More file actions
28 lines (27 loc) · 745 Bytes
/
2381.cpp
File metadata and controls
28 lines (27 loc) · 745 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class Solution {
public:
string shiftingLetters(string s, vector<vector<int>>& shifts) {
int n = s.size();
vector<int> diff(n + 1, 0);
for (auto& shift : shifts) {
int start = shift[0];
int end = shift[1];
int move = (shift[2] == 0) ? -1 : 1;
diff[start] += move;
diff[end + 1] -= move;
}
int currMove = 0;
string res;
for (int i = 0; i < n; ++i) {
currMove += diff[i];
int c = s[i] - 'a';
c += currMove + 52;
c %= 26;
c += 52;
c %= 26;
//cout << c << endl;
res.push_back(c + 'a');
}
return res;
}
};