Skip to content

Commit 5ffeef8

Browse files
committed
Add solution #1641
1 parent 415f42b commit 5ffeef8

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,442 LeetCode solutions in JavaScript
1+
# 1,443 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1265,6 +1265,7 @@
12651265
1638|[Count Substrings That Differ by One Character](./solutions/1638-count-substrings-that-differ-by-one-character.js)|Medium|
12661266
1639|[Number of Ways to Form a Target String Given a Dictionary](./solutions/1639-number-of-ways-to-form-a-target-string-given-a-dictionary.js)|Hard|
12671267
1640|[Check Array Formation Through Concatenation](./solutions/1640-check-array-formation-through-concatenation.js)|Easy|
1268+
1641|[Count Sorted Vowel Strings](./solutions/1641-count-sorted-vowel-strings.js)|Medium|
12681269
1657|[Determine if Two Strings Are Close](./solutions/1657-determine-if-two-strings-are-close.js)|Medium|
12691270
1668|[Maximum Repeating Substring](./solutions/1668-maximum-repeating-substring.js)|Easy|
12701271
1669|[Merge In Between Linked Lists](./solutions/1669-merge-in-between-linked-lists.js)|Medium|
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* 1641. Count Sorted Vowel Strings
3+
* https://leetcode.com/problems/count-sorted-vowel-strings/
4+
* Difficulty: Medium
5+
*
6+
* Given an integer n, return the number of strings of length n that consist only of vowels
7+
* (a, e, i, o, u) and are lexicographically sorted.
8+
*
9+
* A string s is lexicographically sorted if for all valid i, s[i] is the same as or comes
10+
* before s[i+1] in the alphabet.
11+
*/
12+
13+
/**
14+
* @param {number} n
15+
* @return {number}
16+
*/
17+
var countVowelStrings = function(n) {
18+
const vowelCounts = [1, 1, 1, 1, 1];
19+
20+
for (let i = 1; i < n; i++) {
21+
for (let j = 3; j >= 0; j--) {
22+
vowelCounts[j] += vowelCounts[j + 1];
23+
}
24+
}
25+
26+
return vowelCounts.reduce((sum, count) => sum + count, 0);
27+
};

0 commit comments

Comments
 (0)