-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path788.cpp
More file actions
35 lines (35 loc) · 991 Bytes
/
Copy path788.cpp
File metadata and controls
35 lines (35 loc) · 991 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class Solution {
public:
int rotatedDigits(int N) {
int total = 0;
for (int i = 2; i <= N; ++i) {
int j = i;
bool valid = true;
int rotated = 0, cur = 1;
while (j > 0) {
int temp = j % 10;
if (temp == 1 || temp == 8 || temp == 0)
rotated += temp * cur;
else if (temp == 2)
rotated += 5 * cur;
else if (temp == 5)
rotated += 2 * cur;
else if (temp == 6)
rotated += 9 * cur;
else if (temp == 9)
rotated += 6 * cur;
else {
valid = false;
break;
}
cur *= 10;
j /= 10;
}
if (!valid)
continue;
if (i != rotated)
++total;
}
return total;
}
};