Skip to content

Commit 3439bc1

Browse files
authored
feat: add typescript solution to lc problem: No.2062 (doocs#611)
No.2062.Count Vowel Substrings of a String
1 parent 90d21ff commit 3439bc1

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed

solution/2000-2099/2062.Count Vowel Substrings of a String/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,40 @@
8686

8787
```
8888

89+
### **TypeScript**
90+
91+
```ts
92+
function countVowelSubstrings(word: string): number {
93+
const n = word.length;
94+
let left = 0, right = 0;
95+
let ans = 0;
96+
while (right < n) {
97+
if (!isVowel(word.charAt(right))) {
98+
// 移动左指针
99+
left = right + 1;
100+
} else {
101+
let cur = word.substring(left, right + 1).split('');
102+
while (cur.length > 0) {
103+
if (isValiedArr(cur)) {
104+
ans++;
105+
}
106+
cur.shift();
107+
}
108+
}
109+
right++;
110+
}
111+
return ans;
112+
};
113+
114+
function isVowel (char: string): boolean {
115+
return ['a', 'e', 'i', 'o', 'u'].includes(char);
116+
}
117+
118+
function isValiedArr(arr: Array<string>): boolean {
119+
return new Set(arr).size == 5;
120+
}
121+
```
122+
89123
### **...**
90124

91125
```

solution/2000-2099/2062.Count Vowel Substrings of a String/README_EN.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,40 @@
7575

7676
```
7777

78+
### **TypeScript**
79+
80+
```ts
81+
function countVowelSubstrings(word: string): number {
82+
const n = word.length;
83+
let left = 0, right = 0;
84+
let ans = 0;
85+
while (right < n) {
86+
if (!isVowel(word.charAt(right))) {
87+
// 移动左指针
88+
left = right + 1;
89+
} else {
90+
let cur = word.substring(left, right + 1).split('');
91+
while (cur.length > 0) {
92+
if (isValiedArr(cur)) {
93+
ans++;
94+
}
95+
cur.shift();
96+
}
97+
}
98+
right++;
99+
}
100+
return ans;
101+
};
102+
103+
function isVowel (char: string): boolean {
104+
return ['a', 'e', 'i', 'o', 'u'].includes(char);
105+
}
106+
107+
function isValiedArr(arr: Array<string>): boolean {
108+
return new Set(arr).size == 5;
109+
}
110+
```
111+
78112
### **...**
79113

80114
```
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
function countVowelSubstrings(word: string): number {
2+
const n = word.length;
3+
let left = 0, right = 0;
4+
let ans = 0;
5+
while (right < n) {
6+
if (!isVowel(word.charAt(right))) {
7+
// 移动左指针
8+
left = right + 1;
9+
} else {
10+
let cur = word.substring(left, right + 1).split('');
11+
while (cur.length > 0) {
12+
if (isValiedArr(cur)) {
13+
ans++;
14+
}
15+
cur.shift();
16+
}
17+
}
18+
right++;
19+
}
20+
return ans;
21+
};
22+
23+
function isVowel (char: string): boolean {
24+
return ['a', 'e', 'i', 'o', 'u'].includes(char);
25+
}
26+
27+
function isValiedArr(arr: Array<string>): boolean {
28+
return new Set(arr).size == 5;
29+
}

0 commit comments

Comments
 (0)