leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0788.cpp (735B)


      1 class Solution {
      2     typedef array<int, 10001> record;
      3     static constexpr const record cache = []() constexpr {
      4         record res = {0};
      5         int cnt = 0;
      6         for (int i = 1; i < size(res); i++) {
      7             int crnt = i, mirror = 1;
      8             do {
      9                 const int digit = crnt % 10;
     10                 if (digit == 3 || digit == 4 || digit == 7) {
     11                     mirror = 1;
     12                     break;
     13                 }
     14                 if (digit != 0 && digit != 1 && digit != 8) mirror = 0;
     15             } while ((crnt /= 10) > 0);
     16             if (!mirror) cnt++;
     17             res[i] = cnt;
     18         }
     19         return res;
     20     }();
     21 
     22   public:
     23     constexpr int rotatedDigits(int n) const { return cache[n]; }
     24 };