LeetCodeDiary

A Diary for solving LeetCode problems

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

动态规划 数学

https://leetcode-cn.com/problems/count-sorted-vowel-strings/solution/

数学插板法真的很难理解 https://leetcode-cn.com/problems/count-sorted-vowel-strings/solution/zhong-xue-shu-xue-ke-pu-n-ge-xiao-qiu-fang-dao-m-g/

class Solution:
    def countVowelStrings(self, n: int) -> int:
        if n == 0:
            return 0
        if n == 1:
            return 5
        count = [1] * 5
        for _ in range(n-2):
            for i in range(1,5):
                count[i] += count[i-1]
        return 5*count[0] + 4*count[1]+ 3*count[2]+ 2*count[3]+ count[4]