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