Skip to content

Latest commit

 

History

History
33 lines (25 loc) · 676 Bytes

1641.Count-Sorted-Vowel-Strings.md

File metadata and controls

33 lines (25 loc) · 676 Bytes

1641. Count Sorted Vowel Strings

Difficulty: Medium

URL

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

Solution

Approach 1: Backtracking

class Solution:
    def countVowelStrings(self, n: int) -> int:
        d = ['a', 'e', 'i', 'o', 'u']
        path = []
        count = 0
        
        def backtracking(n, start):
            nonlocal count
            if n == 0:
                count += 1
                return
            for i in range(start, 5):
                path.append(d[i])
                backtracking(n-1, i)
                path.pop()
            return
        
        backtracking(n, 0)
        return count