Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README_EN.md with Java Solution with O(n) time and O(1) space Complexity. #1897

Merged
merged 4 commits into from
Oct 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions solution/1200-1299/1220.Count Vowels Permutation/README.md
Original file line number Diff line number Diff line change
@@ -249,6 +249,32 @@ class Solution {
}
```

```java
class Solution {
public int countVowelPermutation(int n) {
final int mod = 1000000007;
long countA = 1, countE = 1, countI = 1, countO = 1, countU = 1;
for (int length = 1; length < n; length++) {
// Calculate the next counts for each vowel based on the previous counts
long nextCountA = countE;
long nextCountE = (countA + countI) % mod;
long nextCountI = (countA + countE + countO + countU) % mod;
long nextCountO = (countI + countU) % mod;
long nextCountU = countA;
// Update the counts with the newly calculated values for the next length
countA = nextCountA;
countE = nextCountE;
countI = nextCountI;
countO = nextCountO;
countU = nextCountU;
}
// Calculate the total count of valid strings for length n
long totalCount = (countA + countE + countI + countO + countU) % mod;
return (int) totalCount;
}
}
```

### **C++**

```cpp
26 changes: 26 additions & 0 deletions solution/1200-1299/1220.Count Vowels Permutation/README_EN.md
Original file line number Diff line number Diff line change
@@ -215,6 +215,32 @@ class Solution {
}
```

```java
class Solution {
public int countVowelPermutation(int n) {
final int mod = 1000000007;
long countA = 1, countE = 1, countI = 1, countO = 1, countU = 1;
for (int length = 1; length < n; length++) {
// Calculate the next counts for each vowel based on the previous counts
long nextCountA = countE;
long nextCountE = (countA + countI) % mod;
long nextCountI = (countA + countE + countO + countU) % mod;
long nextCountO = (countI + countU) % mod;
long nextCountU = countA;
// Update the counts with the newly calculated values for the next length
countA = nextCountA;
countE = nextCountE;
countI = nextCountI;
countO = nextCountO;
countU = nextCountU;
}
// Calculate the total count of valid strings for length n
long totalCount = (countA + countE + countI + countO + countU) % mod;
return (int) totalCount;
}
}
```

### **C++**

```cpp