Skip to content

Commit

Permalink
feat: add solutions to lc problems: No.2559 (#3918)
Browse files Browse the repository at this point in the history
  • Loading branch information
rain84 authored Jan 3, 2025
1 parent ac790ab commit ef0677c
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 27 deletions.
32 changes: 23 additions & 9 deletions solution/2500-2599/2559.Count Vowel Strings in Ranges/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,15 +306,29 @@ func vowelStrings(words []string, queries [][]int) []int {
```ts
function vowelStrings(words: string[], queries: number[][]): number[] {
const vowels = new Set(['a', 'e', 'i', 'o', 'u']);
const n = words.length;
const s: number[] = new Array(n + 1).fill(0);
for (let i = 0; i < n; ++i) {
if (vowels.has(words[i][0]) && vowels.has(words[i][words[i].length - 1])) {
s[i + 1] = s[i] + 1;
} else {
s[i + 1] = s[i];
}
}
const s = new Array(words.length + 1).fill(0);

words.forEach((w, i) => {
const x = +(vowels.has(w[0]) && vowels.has(w.at(-1)!));
s[i + 1] = s[i] + x;
});

return queries.map(([l, r]) => s[r + 1] - s[l]);
}
```

#### JavaScript

```js
function vowelStrings(words, queries) {
const vowels = new Set(['a', 'e', 'i', 'o', 'u']);
const s = new Array(words.length + 1).fill(0);

words.forEach((w, i) => {
const x = +(vowels.has(w[0]) && vowels.has(w.at(-1)));
s[i + 1] = s[i] + x;
});

return queries.map(([l, r]) => s[r + 1] - s[l]);
}
```
Expand Down
32 changes: 23 additions & 9 deletions solution/2500-2599/2559.Count Vowel Strings in Ranges/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,29 @@ func vowelStrings(words []string, queries [][]int) []int {
```ts
function vowelStrings(words: string[], queries: number[][]): number[] {
const vowels = new Set(['a', 'e', 'i', 'o', 'u']);
const n = words.length;
const s: number[] = new Array(n + 1).fill(0);
for (let i = 0; i < n; ++i) {
if (vowels.has(words[i][0]) && vowels.has(words[i][words[i].length - 1])) {
s[i + 1] = s[i] + 1;
} else {
s[i + 1] = s[i];
}
}
const s = new Array(words.length + 1).fill(0);

words.forEach((w, i) => {
const x = +(vowels.has(w[0]) && vowels.has(w.at(-1)!));
s[i + 1] = s[i] + x;
});

return queries.map(([l, r]) => s[r + 1] - s[l]);
}
```

#### JavaScript

```js
function vowelStrings(words, queries) {
const vowels = new Set(['a', 'e', 'i', 'o', 'u']);
const s = new Array(words.length + 1).fill(0);

words.forEach((w, i) => {
const x = +(vowels.has(w[0]) && vowels.has(w.at(-1)));
s[i + 1] = s[i] + x;
});

return queries.map(([l, r]) => s[r + 1] - s[l]);
}
```
Expand Down
11 changes: 11 additions & 0 deletions solution/2500-2599/2559.Count Vowel Strings in Ranges/Solution2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function vowelStrings(words, queries) {
const vowels = new Set(['a', 'e', 'i', 'o', 'u']);
const s = new Array(words.length + 1).fill(0);

words.forEach((w, i) => {
const x = +(vowels.has(w[0]) && vowels.has(w.at(-1)));
s[i + 1] = s[i] + x;
});

return queries.map(([l, r]) => s[r + 1] - s[l]);
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
function vowelStrings(words: string[], queries: number[][]): number[] {
const vowels = new Set(['a', 'e', 'i', 'o', 'u']);
const n = words.length;
const s: number[] = new Array(n + 1).fill(0);
for (let i = 0; i < n; ++i) {
if (vowels.has(words[i][0]) && vowels.has(words[i][words[i].length - 1])) {
s[i + 1] = s[i] + 1;
} else {
s[i + 1] = s[i];
}
}
const s = new Array(words.length + 1).fill(0);

words.forEach((w, i) => {
const x = +(vowels.has(w[0]) && vowels.has(w.at(-1)!));
s[i + 1] = s[i] + x;
});

return queries.map(([l, r]) => s[r + 1] - s[l]);
}

0 comments on commit ef0677c

Please sign in to comment.