当前位置:网站首页>LeetCode 1641. Count the number of Lexicographic vowel strings
LeetCode 1641. Count the number of Lexicographic vowel strings
2022-07-06 16:43:00 【Daylight629】
1641. Count the number of vowel strings in the dictionary
Give you an integer n, Please return the length of n 、 Only by vowels (a, e, i, o, u) Composed and in accordance with Dictionary order The number of strings .
character string s Press Dictionary order Need to meet : For all that works i,s[i] The position in the alphabet is always the same as s[i+1] Same or in s[i+1] Before .
Example 1:
Input :n = 1
Output :5
explain : Consisting of only vowels 5 Dictionary order strings are ["a","e","i","o","u"]
Example 2:
Input :n = 2
Output :15
explain : Consisting of only vowels 15 Dictionary order strings are
["aa","ae","ai","ao","au","ee","ei","eo","eu","ii","io","iu","oo","ou","uu"]
Be careful ,"ea" It's not a string according to the meaning of the question , because 'e' Position in the alphabet than 'a' be in the rear
Example 3:
Input :n = 33
Output :66045
Tips :
1 <= n <= 50
Two 、 Method 1
Dynamic gauge , Completely backpack
class Solution {
public int countVowelStrings(int n) {
int[] dp = new int[6];
for (int i = 1; i <= 5; i++) {
dp[i] = 1;
}
for (int j = 2; j <= n; j++) {
for (int i = 2; i <= 5; i++) {
dp[i] += dp[i - 1];
}
}
return dp[1] + dp[2] + dp[3] + dp[4] + dp[5];
}
}
Complexity analysis
Time complexity :O(n).
Spatial complexity :O(1).
3、 ... and 、 Method 2
Permutation and combination , Diaphragm method 
class Solution {
public int countVowelStrings(int n) {
return (n + 4) * (n + 3) * (n + 2) * (n + 1) / 24;
}
}
Complexity analysis
Time complexity :O(1).
Spatial complexity :O(1).
边栏推荐
- Input can only input numbers, limited input
- Installation and use of VMware Tools and open VM tools: solve the problems of incomplete screen and unable to transfer files of virtual machines
- OneForAll安装使用
- MP4格式详解
- Educational Codeforces Round 122 (Rated for Div. 2)
- Codeforces Round #798 (Div. 2)A~D
- MariaDB的安装与配置
- 软通乐学-js求字符串中字符串当中那个字符出现的次数多 -冯浩的博客
- 第5章 消费者组详解
- 300th weekly match - leetcode
猜你喜欢

我在字节跳动「修电影」

ByteDance new programmer's growth secret: those glittering treasures mentors

Use JQ to realize the reverse selection of all and no selection at all - Feng Hao's blog

QT implementation fillet window

Basic principles of video compression coding and audio compression coding

Cmake Express

Solve the problem that intel12 generation core CPU single thread only runs on small cores

Mp4 format details

解决Intel12代酷睿CPU单线程只给小核运行的问题

新手必会的静态站点生成器——Gridsome
随机推荐
(POJ - 1458) common subsequence (longest common subsequence)
Problem - 922D、Robot Vacuum Cleaner - Codeforces
China tetrabutyl urea (TBU) market trend report, technical dynamic innovation and market forecast
Investigation report of bench type Brinell hardness tester industry - market status analysis and development prospect prediction
Anaconda下安装Jupyter notebook
sublime text 代码格式化操作
Research Report on market supply and demand and strategy of double drum magnetic separator industry in China
去掉input聚焦时的边框
Codeforces Round #798 (Div. 2)A~D
Codeforces Round #771 (Div. 2)
Simple records of business system migration from Oracle to opengauss database
Spark独立集群Worker和Executor的概念
Spark independent cluster dynamic online and offline worker node
VMware Tools和open-vm-tools的安装与使用:解决虚拟机不全屏和无法传输文件的问题
Log statistics (double pointer)
It is forbidden to trigger onchange in antd upload beforeupload
Codeforces Round #803 (Div. 2)A~C
Effet d'utilisation, déclenché lorsque les composants de la fonction sont montés et déchargés
Li Kou leetcode 280 weekly match
Chapter 1 overview of MapReduce