# 【LeetCode】1056. Confusing Number 解题报告(C++)

900 篇文章 155 订阅
1033 篇文章 56 订阅

## 题目描述

Given a number N, return true if and only if it is a confusing number, which satisfies the following condition:

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. A confusing number is a number that when rotated 180 degrees becomes a different number with each digit valid.

Example 1:

Input: 6
Output: true
Explanation:
We get 9 after rotating 6, 9 is a valid number and 9!=6.


Example 2:

Input: 89
Output: true
Explanation:
We get 68 after rotating 89, 86 is a valid number and 86!=89.


Example 3:

Input: 11
Output: false
Explanation:
We get 11 after rotating 11, 11 is a valid number but the value remains the same, thus 11 is not a confusing number.


Example 4:

Input: 25
Output: false
Explanation:
We get an invalid number after rotating 25.


Note:

1. 0 <= N <= 10^9
2. After the rotation we can ignore leading zeros, for example if after rotation we have 0008 then this number is considered as just 8.

## 题目大意

2, 3, 4, 5, 7 旋转 180° 后，得到的不是数字。

## 解题方法

### 字典

C++代码如下：

class Solution {
public:
bool confusingNumber(int N) {
unordered_map<int, int> m{{0, 0}, {1, 1}, {6, 9}, {8, 8}, {9, 6}};
int rotate = 0;
int temp = N;
while (temp != 0) {
int mod = temp % 10;
if (!m.count(mod))
return false;
rotate = 10 * rotate + m[mod];
temp /= 10;
}
return rotate != N;
}
};


## 日期

2019 年 9 月 18 日 —— 今日又是九一八

• 0
点赞
• 1
收藏
• 打赏
• 0
评论
10-30 169
06-18 362
05-12 499
09-29 1223
05-27 1156
10-13 274
09-21 439
04-19 192
10-23 186
03-05 1654
03-30 2827

### “相关推荐”对你有帮助么？

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

¥2 ¥4 ¥6 ¥10 ¥20

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。