-
Notifications
You must be signed in to change notification settings - Fork 3
/
1088.cpp
24 lines (24 loc) · 850 Bytes
/
1088.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Solution {
public:
vector<pair<int, int>> pairs = {{0, 0}, {1, 1}, {6, 9}, {8, 8}, {9, 6}};
vector<long long> power = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000};
int res = 0;
void backtracking(int n, int curr, long long currInt, long long reverseInt) {
if (currInt > n) return;
if (currInt >= 1 && currInt <= n) {
if (currInt != reverseInt) {
res++;
}
}
for (auto& [f, r] : pairs) {
if (curr == 0 && f == 0) continue;
backtracking(n, curr + 1, currInt * 10 + f, reverseInt + r * power[curr]);
}
}
int confusingNumberII(int n) {
long long currInt = 0;
long long reverseInt = 0;
backtracking(n, 0, currInt, reverseInt);
return res;
}
};