LC: 1056. Confusing Number - spiralgo/algorithms GitHub Wiki
1056. Confusing Number:
The Essence:
If a number:
- consists of these digits:
0, 1, 6, 8, 9 - and it is not equal itself when rotated 180 degrees, is a
confusing number.
Details: We can use a map implementation to store each pairs like:
map.put(6, 9);
map.put(9, 6);
map.put(0, 0);
map.put(1, 1);
map.put(8, 8);
We can simulate rotating the number 180 degrees by splitting it into its digits and reconstructing the number from the end. Then we can check if the number equals its rotated version.