503. Confusing Number
A confusing number is a number that, when rotated 180 degrees, becomes a different valid number.
We can rotate digits of a number as follows:
Valid Rotations:
- 0 → 0
- 1 → 1
- 6 → 9
- 8 → 8
- 9 → 6
Invalid Digits:
- 2, 3, 4, 5, 7 (these cannot be rotated)
After rotating a number, leading zeros can be ignored.
Given an integer n, return true if it is a confusing number, otherwise return false.
Example 1:
Input: n = 19
Output: true
Explanation: Rotating 19 gives 61, which is valid and different from 19.
Example 2:
Input: n = 100
Output: true
Explanation: Rotating 100 gives 001, which is just 1, different from the original.
Now Your Turn!
Pick the correct output for the given inputInput: n = 69
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
0 <= n < 109