An integer x is good if rotating each of its digits by 180 degrees gives a valid number that is different from x. 0, 1 and 8 rotate to themselves, 2 and 5 rotate to each other, 6 and 9 rotate to each other, and 3, 4 and 7 cannot be rotated. Given n, return how many integers in [1, n] are good.
An integer x is good if rotating each of its digits by 180 degrees gives a valid number that is different from x. 0, 1 and 8 rotate to themselves, 2 and 5 rotate to each other, 6 and 9 rotate to each other, and 3, 4 and 7 cannot be rotated. Given n, return how many integers in [1, n] are good.
Example 1:
Input: {"n":10}
Output: 4
Constraints:
1≤n≤104
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"n":10}
Class each digit: 0, 1, 8 rotate to themselves; 2, 5, 6, 9 rotate to a different digit; 3, 4, 7 break the number.
kind[d]: what each digit becomes after a 180 degree turn