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