-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path3335.cpp
More file actions
26 lines (26 loc) · 743 Bytes
/
3335.cpp
File metadata and controls
26 lines (26 loc) · 743 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
class Solution {
public:
int lengthAfterTransformations(string s, int t) {
long long res = 0;
long long mod = 1e9 + 7;
vector<long long> hash(26, 0);
vector<long long> hashTemp(26, 0);
for (auto& c : s) hash[c - 'a']++;
for (int i = 0; i < t; ++i) {
for (int i = 0; i < 25; ++i) {
hashTemp[i + 1] = hash[i];
}
hashTemp[0] = hash[25];
hashTemp[1] += hash[25];
for (int i = 0; i < 26; ++i) {
hash[i] = hashTemp[i];
hash[i] %= mod;
}
}
for (int i = 0; i < 26; ++i) {
res += hash[i];
res %= mod;
}
return res;
}
};