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 f346caf

Browse files
iancarsonyanglbme
andauthored
feat: add java solution to lc problem: No.1220 (doocs#1897)
--------- Co-authored-by: iancarson <iancarson@users.noreply.github.com> Co-authored-by: Libin YANG <contact@yanglibin.info>
1 parent fd17349 commit f346caf

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

‎solution/1200-1299/1220.Count Vowels Permutation/README.md‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,32 @@ class Solution {
249249
}
250250
```
251251

252+
```java
253+
class Solution {
254+
public int countVowelPermutation(int n) {
255+
final int mod = 1000000007;
256+
long countA = 1, countE = 1, countI = 1, countO = 1, countU = 1;
257+
for (int length = 1; length < n; length++) {
258+
// Calculate the next counts for each vowel based on the previous counts
259+
long nextCountA = countE;
260+
long nextCountE = (countA + countI) % mod;
261+
long nextCountI = (countA + countE + countO + countU) % mod;
262+
long nextCountO = (countI + countU) % mod;
263+
long nextCountU = countA;
264+
// Update the counts with the newly calculated values for the next length
265+
countA = nextCountA;
266+
countE = nextCountE;
267+
countI = nextCountI;
268+
countO = nextCountO;
269+
countU = nextCountU;
270+
}
271+
// Calculate the total count of valid strings for length n
272+
long totalCount = (countA + countE + countI + countO + countU) % mod;
273+
return (int) totalCount;
274+
}
275+
}
276+
```
277+
252278
### **C++**
253279

254280
```cpp

‎solution/1200-1299/1220.Count Vowels Permutation/README_EN.md‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,32 @@ class Solution {
215215
}
216216
```
217217

218+
```java
219+
class Solution {
220+
public int countVowelPermutation(int n) {
221+
final int mod = 1000000007;
222+
long countA = 1, countE = 1, countI = 1, countO = 1, countU = 1;
223+
for (int length = 1; length < n; length++) {
224+
// Calculate the next counts for each vowel based on the previous counts
225+
long nextCountA = countE;
226+
long nextCountE = (countA + countI) % mod;
227+
long nextCountI = (countA + countE + countO + countU) % mod;
228+
long nextCountO = (countI + countU) % mod;
229+
long nextCountU = countA;
230+
// Update the counts with the newly calculated values for the next length
231+
countA = nextCountA;
232+
countE = nextCountE;
233+
countI = nextCountI;
234+
countO = nextCountO;
235+
countU = nextCountU;
236+
}
237+
// Calculate the total count of valid strings for length n
238+
long totalCount = (countA + countE + countI + countO + countU) % mod;
239+
return (int) totalCount;
240+
}
241+
}
242+
```
243+
218244
### **C++**
219245

220246
```cpp

0 commit comments

Comments
(0)

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