LeetCode 1641 Count Sorted Vowel Strings (Python)

Posted by 小明MaxMing on January 17, 2021

题目

Given an integer n, return the number of strings of length n that consist only of vowels (a, e, i, o, u) and are lexicographically sorted.

A string s is lexicographically sorted if for all valid i, s[i] is the same as or comes before s[i+1] in the alphabet.

解题思路

排列组合问题,相当于把n个小球,分成5个部分,一共有多少分法

代码

class Solution:
    def countVowelStrings(self, n: int) -> int:
        return math.comb(n + 4, 4)

视频讲解 YouTube<--欢迎点击订阅

视频讲解 bilibili<--欢迎点击订阅