Re: [閒聊] 每日leetcode
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
08/11 01:18, 1F
討論串 (同標題文章)
完整討論串 (本文為第 1497 之 1548 篇):