【題解】LeetCode 1641. Count Sorted Vowel Strings

【題目敘述】https://leetcode.com/problems/count-sorted-vowel-strings/

class Solution {
public:
    int countVowelStrings(int n) {
        int dp[55][5] = {};
        for (int i = 0; i < 5; i++){
            dp[0][i] = 1;
        }
        for (int i = 1; i <= n; i++){
            for (int j = 0; j < 5; j++){
                if (j == 0) dp[i][j] = dp[i-1][j];
                else dp[i][j] = dp[i-1][j]+dp[i][j-1];
            }
        }
        return dp[n][4];
    }
};
分享本文 Share with friends