|
| 1 | +<!--|This file generated by command(leetcode description); DO NOT EDIT. |--> |
| 2 | +<!--+----------------------------------------------------------------------+--> |
| 3 | +<!--|@author Openset <[email protected]> |--> |
| 4 | +<!--|@link https://github.com/openset |--> |
| 5 | +<!--|@home https://github.com/openset/leetcode |--> |
| 6 | +<!--+----------------------------------------------------------------------+--> |
| 7 | + |
| 8 | +[< Previous](https://github.com/openset/leetcode/tree/master/problems/brace-expansion "Brace Expansion") |
| 9 | + |
| 10 | +[Next >](https://github.com/openset/leetcode/tree/master/problems/duplicate-zeros "Duplicate Zeros") |
| 11 | + |
| 12 | +## 1088. Confusing Number II (Hard) |
| 13 | + |
| 14 | +<p>We can rotate digits by 180 degrees to form new digits. When 0, 1, 6, 8, 9 are rotated 180 degrees, they become 0, 1, 9, 8, 6 respectively. When 2, 3, 4, 5 and 7 are rotated 180 degrees, they become invalid.</p> |
| 15 | + |
| 16 | +<p>A <em>confusing number</em> is a number that when rotated 180 degrees becomes a <strong>different</strong> number with each digit valid.(Note that the rotated number can be greater than the original number.)</p> |
| 17 | + |
| 18 | +<p>Given a positive integer <code>N</code>, return the number of confusing numbers between <code>1</code> and <code>N</code> inclusive.</p> |
| 19 | + |
| 20 | +<p> </p> |
| 21 | + |
| 22 | +<p><strong>Example 1:</strong></p> |
| 23 | + |
| 24 | +<pre> |
| 25 | +<strong>Input: </strong><span id="example-input-1-1">20</span> |
| 26 | +<strong>Output: </strong><span id="example-output-1">6</span> |
| 27 | +<strong>Explanation: </strong> |
| 28 | +The confusing numbers are [6,9,10,16,18,19]. |
| 29 | +6 converts to 9. |
| 30 | +9 converts to 6. |
| 31 | +10 converts to 01 which is just 1. |
| 32 | +16 converts to 91. |
| 33 | +18 converts to 81. |
| 34 | +19 converts to 61. |
| 35 | +</pre> |
| 36 | + |
| 37 | +<p><strong>Example 2:</strong></p> |
| 38 | + |
| 39 | +<pre> |
| 40 | +<strong>Input: </strong><span id="example-input-2-1">100</span> |
| 41 | +<strong>Output: </strong><span id="example-output-2">19</span> |
| 42 | +<strong>Explanation: </strong> |
| 43 | +The confusing numbers are [6,9,10,16,18,19,60,61,66,68,80,81,86,89,90,91,98,99,100]. |
| 44 | +</pre> |
| 45 | + |
| 46 | +<p> </p> |
| 47 | + |
| 48 | +<p><strong>Note:</strong></p> |
| 49 | + |
| 50 | +<ol> |
| 51 | + <li><code>1 <= N <= 10^9</code></li> |
| 52 | +</ol> |
| 53 | + |
| 54 | +### Related Topics |
| 55 | + [[Math](https://github.com/openset/leetcode/tree/master/tag/math/README.md)] |
| 56 | + [[Backtracking](https://github.com/openset/leetcode/tree/master/tag/backtracking/README.md)] |
| 57 | + |
| 58 | +### Similar Questions |
| 59 | + 1. [Confusing Number](https://github.com/openset/leetcode/tree/master/problems/confusing-number) (Easy) |
| 60 | + |
| 61 | +### Hints |
| 62 | +<details> |
| 63 | +<summary>Hint 1</summary> |
| 64 | +Which set of digits have the valid numbers? |
| 65 | +</details> |
| 66 | + |
| 67 | +<details> |
| 68 | +<summary>Hint 2</summary> |
| 69 | +Only 0, 1, 6, 8, 9 are the valid set of digits, do a backtracking to generate all the numbers containing this digits and check they are valid. |
| 70 | +</details> |
0 commit comments