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 4d86b30

Browse files
feat: add typescript solution to lc problem: No.2063 (doocs#610)
No.2063.Vowels of All Substrings
1 parent b3b7a68 commit 4d86b30

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

‎solution/2000-2099/2063.Vowels of All Substrings/README.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666

6767
<!-- 这里可写通用的实现逻辑 -->
6868

69+
判断word[i]是否为元音,且在所有子字符串中一共出现了 (i+1)*(n-i) 次
70+
6971
<!-- tabs:start -->
7072

7173
### **Python3**
@@ -84,6 +86,22 @@
8486

8587
```
8688

89+
### **TypeScript**
90+
91+
```ts
92+
function countVowels(word: string): number {
93+
const n = word.length;
94+
let ans = 0;
95+
for (let i = 0; i < n; i++) {
96+
let char = word.charAt(i);
97+
if (['a', 'e', 'i', 'o', 'u'].includes(char)) {
98+
ans += ((i + 1) * (n - i));
99+
}
100+
}
101+
return ans;
102+
};
103+
```
104+
87105
### **...**
88106

89107
```

‎solution/2000-2099/2063.Vowels of All Substrings/README_EN.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,22 @@ Hence, the total sum of vowels = 1 +たす 1 +たす 1 +たす 0 +たす 0 +たす 0 = 3. </pre>
6969

7070
```
7171

72+
### **TypeScript**
73+
74+
```ts
75+
function countVowels(word: string): number {
76+
const n = word.length;
77+
let ans = 0;
78+
for (let i = 0; i < n; i++) {
79+
let char = word.charAt(i);
80+
if (['a', 'e', 'i', 'o', 'u'].includes(char)) {
81+
ans += ((i + 1) * (n - i));
82+
}
83+
}
84+
return ans;
85+
};
86+
```
87+
7288
### **Java**
7389

7490
```java
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function countVowels(word: string): number {
2+
const n = word.length;
3+
let ans = 0;
4+
for (let i = 0; i < n; i++) {
5+
let char = word.charAt(i);
6+
if (['a', 'e', 'i', 'o', 'u'].includes(char)) {
7+
ans += ((i + 1) * (n - i));
8+
}
9+
}
10+
return ans;
11+
};

0 commit comments

Comments
(0)

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