Skip to content

feat: add typescript solution to lc problem: No.2063.Vowels of All Su… #610

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

Merged
merged 1 commit into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
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
18 changes: 18 additions & 0 deletions solution/2000-2099/2063.Vowels of All Substrings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@

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

判断word[i]是否为元音,且在所有子字符串中一共出现了 (i+1)*(n-i) 次

<!-- tabs:start -->

### **Python3**
Expand All @@ -84,6 +86,22 @@

```

### **TypeScript**

```ts
function countVowels(word: string): number {
const n = word.length;
let ans = 0;
for (let i = 0; i < n; i++) {
let char = word.charAt(i);
if (['a', 'e', 'i', 'o', 'u'].includes(char)) {
ans += ((i + 1) * (n - i));
}
}
return ans;
};
```

### **...**

```
Expand Down
16 changes: 16 additions & 0 deletions solution/2000-2099/2063.Vowels of All Substrings/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@ Hence, the total sum of vowels = 1 + 1 + 1 + 0 + 0 + 0 = 3. </pre>

```

### **TypeScript**

```ts
function countVowels(word: string): number {
const n = word.length;
let ans = 0;
for (let i = 0; i < n; i++) {
let char = word.charAt(i);
if (['a', 'e', 'i', 'o', 'u'].includes(char)) {
ans += ((i + 1) * (n - i));
}
}
return ans;
};
```

### **Java**

```java
Expand Down
11 changes: 11 additions & 0 deletions solution/2000-2099/2063.Vowels of All Substrings/Solution.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function countVowels(word: string): number {
const n = word.length;
let ans = 0;
for (let i = 0; i < n; i++) {
let char = word.charAt(i);
if (['a', 'e', 'i', 'o', 'u'].includes(char)) {
ans += ((i + 1) * (n - i));
}
}
return ans;
};