
[LeetCode] 1415. The k-th Lexicographical String of All Happy Strings of Length n (Python)
·
코딩 테스트
ProblemSolutionrecursive, backtracking3개 문자중에서 n개 만큼 뽑는 순열문제.단, str[i] != str[i+1] 이어야한다. Codeclass Solution: def getHappyString(self, n: int, k: int) -> str: chars = ['a', 'b', 'c'] li = [] def happy(cur): # 문자열 길이가 n이면 종료 if len(cur) == n: li.append(cur) return for char in chars: ..