Re: [閒聊] 每日leetcode

看板Marginalman作者 (6B)時間1年前 (2024/09/21 08:55), 1年前編輯推噓0(003)
留言3則, 2人參與, 1年前最新討論串886/1548 (看更多)
386. lexico什麼的number 題目要求T:O(n), M:O(1) 照字典順序擺 就看前綴 原本想說用radix sort試試 可是memory (n) 雖然應該會過== 改用recursive 先來先擺 能*10就*10 再來能+1就+1 不過要確認他不要加到下一個prefix去 class Solution { public: vector<int> res; vector<int> lexicalOrder(int n) { prefix(1, n); return res; } void prefix(int cur, int& n){ if(cur > n) return; //put all prefix(cur) into res; res.push_back(cur); prefix(cur * 10, n); if((cur + 1) % 10 != 0) prefix(cur + 1, n); } }; ----- Sent from JPTT on my iPad -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.205.121.194 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1726880102.A.5C9.html ※ 編輯: sixB (123.205.121.194 臺灣), 09/21/2024 08:55:36

09/21 09:07, 1年前 , 1F
看到一個用trie的好酷 雖然mon可是
09/21 09:07, 1F

09/21 09:07, 1年前 , 2F
字典題用字典樹超有感覺
09/21 09:07, 2F

09/21 12:08, 1年前 , 3F
大師
09/21 12:08, 3F
文章代碼(AID): #1cxXbcN9 (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1cxXbcN9 (Marginalman)