Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0209afb

Browse files
Create Total Characters in String After Transformations I.java
1 parent c7c43dc commit 0209afb

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution {
2+
3+
private static final int MOD = 1000_0000_07;
4+
5+
public int lengthAfterTransformations(String s, int t) {
6+
int[] frequency = new int[26];
7+
for (char c : s.toCharArray()) {
8+
frequency[c - 'a']++;
9+
}
10+
for (int round = 0; round < t; round++) {
11+
int[] next = new int[26];
12+
next[0] = frequency[25]; // Transformation from 'z'
13+
next[1] = (frequency[25] + frequency[0]) % MOD; // Transformation from either 'z' or 'a'
14+
for (int i = 2; i < 26; i++) {
15+
next[i] = frequency[i - 1]; // Transformation for next character
16+
}
17+
frequency = next;
18+
}
19+
int result = 0;
20+
for (int i = 0; i < 26; i++) {
21+
result = (result + frequency[i]) % MOD;
22+
}
23+
return result;
24+
}
25+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /