Re: [闲聊] 每日leetcode

楼主: Rushia (みけねこ的鼻屎)   2025-02-19 23:01:37
https://leetcode.com/problems/the-k-th-lexicographical-string-of-all-happy-strings-of-length-n
1415. The k-th Lexicographical String of All Happy Strings of Length n
一个好字串是由abc三种字符组成的字串,相邻的字符不相同,求出长度为n的所有好字串
中,字典顺序第k小的好字串是什么。
思路:
1.用dfs穷举所有合法字串组合,做适当的剪枝。
2.把好字串丢到一个Heap里面。
3.最后pop出第k个好字串。
Java Code:

Links booklink

Contact Us: admin [ a t ] ucptt.com