-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDAY0052.cpp
More file actions
39 lines (39 loc) · 1.07 KB
/
DAY0052.cpp
File metadata and controls
39 lines (39 loc) · 1.07 KB
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
29
30
31
32
33
34
35
36
37
38
39
// 3335. Total Characters in String After Transformations I
#define MOD 1000000007
class Solution {
public:
int lengthAfterTransformations(string s, int t) {
// int answer=0;
// vector<int> hashmap(26,0);
// for(int i=0;i<s.size();i++){
// hashmap[s[i]-97]++;
// }
// for(int i=0;i<t;i++){
// vector<int> temp(26,0);
// temp[0]=hashmap[25];
// temp[1]=(hashmap[25]+hashmap[0])%MOD;
// for(int j=2;j<26;j++){
// temp[j]=hashmap[j-1];
// }
// hashmap=temp;
// }
// for(int i=0;i<26;i++){
// answer=(answer+hashmap[i])%MOD;
// }
// return answer;
int cnt[26]={0};
for (char c : s) {
cnt[c-'a']++;
}
int res = s.size();
int z = 25;
for (int i = 0; i < t; i++) {
res += cnt[z];
res %= MOD;
cnt[(z+1)%26] += cnt[z];
cnt[(z+1)%26] %= MOD;
z = (z+25) % 26;
}
return res;
}
};