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 5b0cd14

Browse files
committed
feat: add solutions to lc problem: No.1641
No.1641.Count Sorted Vowel Strings
1 parent 5544e15 commit 5b0cd14

File tree

6 files changed

+161
-4
lines changed

6 files changed

+161
-4
lines changed

‎solution/1600-1699/1641.Count Sorted Vowel Strings/README.md‎

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,27 +45,87 @@
4545
<li><code>1 <= n <= 50</code> </li>
4646
</ul>
4747

48-
4948
## 解法
5049

5150
<!-- 这里可写通用的实现逻辑 -->
5251

52+
```
53+
a e i o u
54+
1 1 1 1 1 n=1
55+
5 4 3 2 1 n=2
56+
15 10 6 3 1 n=3
57+
... n=...
58+
```
59+
5360
<!-- tabs:start -->
5461

5562
### **Python3**
5663

5764
<!-- 这里可写当前语言的特殊实现逻辑 -->
5865

5966
```python
60-
67+
class Solution:
68+
def countVowelStrings(self, n: int) -> int:
69+
cnt = [1] * 5
70+
for i in range(2, n + 1):
71+
for j in range(3, -1, -1):
72+
cnt[j] += cnt[j + 1]
73+
return sum(cnt)
6174
```
6275

6376
### **Java**
6477

6578
<!-- 这里可写当前语言的特殊实现逻辑 -->
6679

6780
```java
81+
class Solution {
82+
public int countVowelStrings(int n) {
83+
int[] cnt = new int[5];
84+
Arrays.fill(cnt, 1);
85+
for (int i = 2; i <= n; ++i) {
86+
for (int j = 3; j >= 0; --j) {
87+
cnt[j] += cnt[j + 1];
88+
}
89+
}
90+
return Arrays.stream(cnt).sum();
91+
}
92+
}
93+
```
94+
95+
### **C++**
96+
97+
```cpp
98+
class Solution {
99+
public:
100+
int countVowelStrings(int n) {
101+
vector<int> cnt(5, 1);
102+
for (int i = 2; i <= n; ++i)
103+
for (int j = 3; j >= 0; --j)
104+
cnt[j] += cnt[j + 1];
105+
return accumulate(cnt.begin(), cnt.end(), 0);
106+
}
107+
};
108+
```
68109
110+
### **Go**
111+
112+
```go
113+
func countVowelStrings(n int) int {
114+
cnt := make([]int, 5)
115+
for i := range cnt {
116+
cnt[i] = 1
117+
}
118+
for i := 2; i <= n; i++ {
119+
for j := 3; j >= 0; j-- {
120+
cnt[j] += cnt[j+1]
121+
}
122+
}
123+
ans := 0
124+
for _, v := range cnt {
125+
ans += v
126+
}
127+
return ans
128+
}
69129
```
70130

71131
### **...**

‎solution/1600-1699/1641.Count Sorted Vowel Strings/README_EN.md‎

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,73 @@ Note that &quot;ea&quot; is not a valid string since &#39;e&#39; comes after &#3
4141
<li><code>1 &lt;= n &lt;= 50</code>&nbsp;</li>
4242
</ul>
4343

44-
4544
## Solutions
4645

4746
<!-- tabs:start -->
4847

4948
### **Python3**
5049

5150
```python
52-
51+
class Solution:
52+
def countVowelStrings(self, n: int) -> int:
53+
cnt = [1] * 5
54+
for i in range(2, n + 1):
55+
for j in range(3, -1, -1):
56+
cnt[j] += cnt[j + 1]
57+
return sum(cnt)
5358
```
5459

5560
### **Java**
5661

5762
```java
63+
class Solution {
64+
public int countVowelStrings(int n) {
65+
int[] cnt = new int[5];
66+
Arrays.fill(cnt, 1);
67+
for (int i = 2; i <= n; ++i) {
68+
for (int j = 3; j >= 0; --j) {
69+
cnt[j] += cnt[j + 1];
70+
}
71+
}
72+
return Arrays.stream(cnt).sum();
73+
}
74+
}
75+
```
76+
77+
### **C++**
78+
79+
```cpp
80+
class Solution {
81+
public:
82+
int countVowelStrings(int n) {
83+
vector<int> cnt(5, 1);
84+
for (int i = 2; i <= n; ++i)
85+
for (int j = 3; j >= 0; --j)
86+
cnt[j] += cnt[j + 1];
87+
return accumulate(cnt.begin(), cnt.end(), 0);
88+
}
89+
};
90+
```
5891
92+
### **Go**
93+
94+
```go
95+
func countVowelStrings(n int) int {
96+
cnt := make([]int, 5)
97+
for i := range cnt {
98+
cnt[i] = 1
99+
}
100+
for i := 2; i <= n; i++ {
101+
for j := 3; j >= 0; j-- {
102+
cnt[j] += cnt[j+1]
103+
}
104+
}
105+
ans := 0
106+
for _, v := range cnt {
107+
ans += v
108+
}
109+
return ans
110+
}
59111
```
60112

61113
### **...**
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution {
2+
public:
3+
int countVowelStrings(int n) {
4+
vector<int> cnt(5, 1);
5+
for (int i = 2; i <= n; ++i)
6+
for (int j = 3; j >= 0; --j)
7+
cnt[j] += cnt[j + 1];
8+
return accumulate(cnt.begin(), cnt.end(), 0);
9+
}
10+
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
func countVowelStrings(n int) int {
2+
cnt := make([]int, 5)
3+
for i := range cnt {
4+
cnt[i] = 1
5+
}
6+
for i := 2; i <= n; i++ {
7+
for j := 3; j >= 0; j-- {
8+
cnt[j] += cnt[j+1]
9+
}
10+
}
11+
ans := 0
12+
for _, v := range cnt {
13+
ans += v
14+
}
15+
return ans
16+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public int countVowelStrings(int n) {
3+
int[] cnt = new int[5];
4+
Arrays.fill(cnt, 1);
5+
for (int i = 2; i <= n; ++i) {
6+
for (int j = 3; j >= 0; --j) {
7+
cnt[j] += cnt[j + 1];
8+
}
9+
}
10+
return Arrays.stream(cnt).sum();
11+
}
12+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Solution:
2+
def countVowelStrings(self, n: int) -> int:
3+
cnt = [1] * 5
4+
for i in range(2, n + 1):
5+
for j in range(3, -1, -1):
6+
cnt[j] += cnt[j + 1]
7+
return sum(cnt)

0 commit comments

Comments
(0)

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