1641. Count Sorted Vowel Strings
Question
Given an integer
n, return the number of strings of lengthnthat consist only of vowels (a,e,i,o,u) and are lexicographically sorted.A string
sis lexicographically sorted if for all validi,s[i]is the same as or comes befores[i+1]in the alphabet.
Solution
动态规划,创建数组dp[]记录以每个字符开头能组成的字符串数量。
由于当长度为1时,每个字符串都能组成一次,因此初始化所有值为1。
n增长时,每一个层级都等于该字符后的所有值相加。
最后得出的结果在下一个层级的第一位。(因为第一位是所有上一个层级加和)
Code
1 | class Solution { |
Solution
递归,使用成员变量计算有效递归次数。
Code
1 | class Solution { |
1641. Count Sorted Vowel Strings
https://xuanhe95.github.io/2022/05/11/1641-Count-Sorted-Vowel-Strings/
