Re: [閒聊] 每日leetcode

看板Marginalman作者 (JerryChung)時間1年前 (2024/09/21 15:34), 1年前編輯推噓0(005)
留言5則, 4人參與, 1年前最新討論串889/1548 (看更多)
https://leetcode.com/problems/lexicographical-numbers 386. Lexicographical Numbers 思路:不會算複雜度 它答案也沒擋 就隨便解了 等哪天會擋複雜度再說 Python Code: class Solution: def lexicalOrder(self, n: int) -> List[int]: ln = len(str(n) return sorted(range(1, n+1), key=lambda x: str(x).ljust(ln, '0')) -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.45.18.118 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1726904079.A.C69.html

09/21 15:36, 1年前 , 1F
Nlogn 但這題有限制時間和空間啊
09/21 15:36, 1F

09/21 15:36, 1年前 , 2F
等Submit會擋再說 :(
09/21 15:36, 2F
※ 編輯: JerryChungYC (114.45.18.118 臺灣), 09/21/2024 15:37:06

09/21 15:40, 1年前 , 3F
大師
09/21 15:40, 3F

09/21 16:05, 1年前 , 4F
看懂遞迴了 不過這樣會比較慢喔
09/21 16:05, 4F

09/21 20:47, 1年前 , 5F
sort會吧
09/21 20:47, 5F
文章代碼(AID): #1cxdSFnf (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1cxdSFnf (Marginalman)