Re: [閒聊] 每日leetcode
看板Marginalman作者JerryChungYC (JerryChung)時間1年前 (2024/09/21 15:34)推噓0(0推 0噓 5→)留言5則, 4人參與討論串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
09/21 15:36, 1F
→
09/21 15:36,
1年前
, 2F
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
09/21 20:47, 5F
討論串 (同標題文章)
完整討論串 (本文為第 889 之 1548 篇):