Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 24 additions & 13 deletions leetcode/1201-1300/1220.Count-Vowels-Permutation/README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
# [1220.Count Vowels Permutation][title]

> [!WARNING|style:flat]
> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm)

## Description
Given an integer `n`, your task is to count how many strings of length `n` can be formed under the following rules:

- Each character is a lower case vowel (`'a'`, `'e'`, `'i'`, `'o'`, `'u'`)
- Each vowel `'a'` may only be followed by an `'e'`.
- Each vowel `'e'` may only be followed by an `'a'` or an `'i'`.
- Each vowel `'i'` **may not** be followed by another `'i'`.
- Each vowel `'o'` may only be followed by an `'i'` or a `'u'`.
- Each vowel `'u'` may only be followed by an `'a'`.

Since the answer may be too large, return it modulo `10^9 + 7`.

**Example 1:**

```
Input: a = "11", b = "1"
Output: "100"
Input: n = 1
Output: 5
Explanation: All possible strings are: "a", "e", "i" , "o" and "u".
```

## 题意
> ...

## 题解
**Example 2:**

### 思路1
> ...
Count Vowels Permutation
```go
```
Input: n = 2
Output: 10
Explanation: All possible strings are: "ae", "ea", "ei", "ia", "ie", "io", "iu", "oi", "ou" and "ua".
```

**Example 3:**

```
Input: n = 5
Output: 68
```

## 结语

Expand Down
25 changes: 23 additions & 2 deletions leetcode/1201-1300/1220.Count-Vowels-Permutation/Solution.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
package Solution

func Solution(x bool) bool {
return x
const mod1220 = 1000000007

// 类似黑白房那个问题
// 结尾两个是黑只能接白的那种感觉 dp 确定是如何结尾的

func Solution(n int) int {
a, e, i, o, u := 1, 1, 1, 1, 1

// 'a': {'e'},
// 'e': {'a', 'i'},
// 'i': {'a', 'e', 'o', 'u'},
// 'o': {'i', 'u'},
// 'u': {'a'},
for idx := 2; idx <= n; idx++ {
// e, i, u后面可以接a
a1 := (e + i + u) % mod1220 // x
e1 := (a + i) % mod1220 //
i1 := (e + o) % mod1220 //
o1 := i % mod1220
u1 := (i + o) % mod1220
a, e, i, o, u = a1, e1, i1, o1, u1
}
return (a + e + i + o + u) % mod1220
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ func TestSolution(t *testing.T) {
// 测试用例
cases := []struct {
name string
inputs bool
expect bool
inputs int
expect int
}{
{"TestCase", true, true},
{"TestCase", true, true},
{"TestCase", false, false},
{"TestCase1", 1, 5},
{"TestCase2", 10, 1739},
{"TestCase3", 100, 173981881},
{"TestCase4", 1000, 89945857},
{"TestCase5", 1798, 324384432},
}

// 开始测试
Expand Down