Re: [閒聊] 每日leetcode

看板Marginalman作者 (6B)時間3月前 (2025/08/11 01:12), 編輯推噓1(100)
留言1則, 1人參與, 3月前最新討論串1497/1548 (看更多)
869. reorderedPower 命名取這樣好皮 字母繞口令 今天的感覺應該有更標準的做法 我只會偷懶做table class Solution { public: bool reorderedPowerOf2(int n) { if(n == 1) return true; vector<vector<int>> cheats; for(int i = 1, cnt = 0; cnt < 32; cnt++, i <<= 1){ vector<int> cheat(10, 0); for(int num = i; num > 0; num /= 10){ cheat[num % 10]++; } cheats.emplace_back(cheat); } vector<int> check(10, 0); for(int num = n; num > 0; num /= 10){ check[num % 10]++; } for(int i = 0; i < 32; i++){ bool res = true; for(int j = 0; j < 10 and res; j++){ if(cheats[i][j] != check[j]){ res = false; break; } } if(res) return res; } return false; } }; -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.135.99.218 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1754845925.A.2FC.html

08/11 01:18, 3月前 , 1F
我只會傻傻的backtrack全部列出來了
08/11 01:18, 1F
文章代碼(AID): #1ecDBbBy (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1ecDBbBy (Marginalman)