반응형
Notice
Recent Posts
Recent Comments
- Today
- Total
작심삼일
[LeetCode] 1641 | Count Sorted Vowel Strings | Python 본문
728x90
반응형
문제 링크: https://leetcode.com/problems/count-sorted-vowel-strings/
문제
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.
조건
- 1 <= n <= 50
내 풀이
순서는 유지하면서 중복은 허용하는 순열의 수를 센다.
itertools의 combinations_with_replacement를 사용하면 바로 구할 수 있다.
코드
from itertools import combinations_with_replacement
class Solution:
def countVowelStrings(self, n: int) -> int:
return len(list(combinations_with_replacement([x for x in range(5)], n)))
728x90
반응형
'스터디 > 코테' 카테고리의 다른 글
[LeetCode] 1091 | Shortest Path in Binary Matrix | Python (0) | 2022.05.16 |
---|---|
[LeetCode] 47 | Permutations II | Python (0) | 2022.05.12 |
[LeetCode] 216 | Combination Sum III | Python (0) | 2022.05.10 |
[LeetCode] 17 | Letter Combinations of a Phone Number | Python (0) | 2022.05.09 |
[LeetCode] 1209 | Remove All Adjacent Duplicates in String II | Python (0) | 2022.05.06 |
Comments