0869.cpp (734B)
1 class Solution { 2 static const unordered_set<string> cache; 3 4 public: 5 bool reorderedPowerOf2(int n) { 6 string digits; 7 do { 8 digits.push_back('0' + n % 10); 9 } while ((n /= 10) > 0); 10 11 sort(begin(digits), end(digits)); 12 return cache.count(digits); 13 } 14 }; 15 16 const unordered_set<string> Solution::cache = { 17 "1", "2", "4", "8", "16", "23", "46", "128", 18 "256", "125", "0124", "0248", "0469", "1289", "13468", "23678", 19 "35566", "011237", "122446", "224588", "0145678", "0122579", "0134449", "0368888", 20 "11266777", "23334455", "01466788", "112234778", "234455668", "012356789"};