leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0788.cpp (735B)
0 class Solution {
1 typedef array<int, 10001> record;
2 static constexpr const record cache = []() constexpr {
3 record res = {0};
4 int cnt = 0;
5 for (int i = 1; i < size(res); i++) {
6 int crnt = i, mirror = 1;
7 do {
8 const int digit = crnt % 10;
9 if (digit == 3 || digit == 4 || digit == 7) {
10 mirror = 1;
11 break;
12 }
13 if (digit != 0 && digit != 1 && digit != 8) mirror = 0;
14 } while ((crnt /= 10) > 0);
15 if (!mirror) cnt++;
16 res[i] = cnt;
17 }
18 return res;
19 }();
21 public:
22 constexpr int rotatedDigits(int n) const { return cache[n]; }
23 };