• 作者: 负雪明烛
  • id: fuxuemingzhu
  • 个人博客:http://fuxuemingzhu.cn/

目录

  • 题目描述
  • 题目大意
  • 解题方法
    • 字典
  • 日期

题目地址:https://leetcode-cn.com/problems/confusing-number/

题目描述

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.

题目大意

给定一个数字 N,当它满足以下条件的时候返回 true:
原数字旋转 180° 以后可以得到新的数字。
如 0, 1, 6, 8, 9 旋转 180° 以后,得到了新的数字 0, 1, 9, 8, 6 。
2, 3, 4, 5, 7 旋转 180° 后,得到的不是数字。
易混淆数 (confusing number) 在旋转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 日 —— 今日又是九一八

【LeetCode】1056. Confusing Number 解题报告(C++)相关推荐

  1. AtCoder Beginner Contest 300G - P-smooth number解题报告

    AtCoder Beginner Contest 300G - P-smooth number解题报告 1 题目链接 传送门 2 题目大意 题目:P-光滑数的数量 题目大意: 在 1 1 1 到 n ...

  2. 【LeetCode】3Sum Closest 解题报告

    [题目] Given an array S of n integers, find three integers in S such that the sum is closest to a give ...

  3. LeetCode Maximum Product Subarray 解题报告

    LeetCode 新题又更新了.求:最大子数组乘积. https://oj.leetcode.com/problems/maximum-product-subarray/ 题目分析:求一个数组,连续子 ...

  4. 【LeetCode】77. Combinations 解题报告(Python C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:递归 方法二:回溯法 日期 题目地址:htt ...

  5. LeetCode 488 Zuma Game 解题报告

    原文链接: http://hankerzheng.com/blog/Leetcode-Zuma-Game- Problem Description LeetCode 488 Zuma Game Thi ...

  6. 洛谷1056 排座椅 解题报告

    洛谷1056 排座椅 本题地址: http://www.luogu.org/problem/show?pid=1056 题目描述 上课的时候总会有一些同学和前后左右的人交头接耳,这是令小学班主任十分头 ...

  7. LeetCode: First Missing Positive 解题报告

    Q: Given an unsorted integer array, find the first missing positive integer. For example, Given [1,2 ...

  8. [Leetcode] 741. Cherry Pickup 解题报告

    题目: In a N x N grid representing a field of cherries, each cell is one of three possible integers. 0 ...

  9. [leetcode] 28. Implement strStr() 解题报告

    题目链接:https://leetcode.com/problems/implement-strstr/ Implement strStr(). Returns the index of the fi ...

  10. [Leetcode] 361. Bomb Enemy 解题报告

    题目: Given a 2D grid, each cell is either a wall 'W', an enemy 'E' or empty '0' (the number zero), re ...

最新文章

  1. 【iOS报错】“The operation couldn’t be completed (LaunchServicesError erro
  2. opencv补全边缘_为什么OpenCV中绘制的轮廓不能填充图像边缘的轮廓?
  3. elasticsearch 嵌入式_Elasticsearch 开箱指南
  4. Java反射机制——获取成员变量构造函数
  5. ARouter源码探究
  6. 在VS中创建多个项目
  7. 字符串匹配算法(KMP)
  8. 重磅!教育部撤销518个高校专业
  9. 华为Mate 30 Pro最新渲染图曝光:六摄造型 越看越顺眼了?
  10. apache mediawiki 安装_MediaWiki初探:安装及使用入门
  11. 08-图8 How Long Does It Take
  12. 两个JS文件使用全局变量并互相调用funciton,JS判断checkbox状态,延迟执行JS语句
  13. 什么情况下你的工作最为成功_在不倦怠的情况下开始成功学习
  14. 《业务需求说明书》检查单 zz
  15. ESTORE OPENCART 清爽现代主题模板 ABC-0063
  16. 字母c语言教学课件,计算机二级考试C语言辅导课件.ppt
  17. 数据库索引到底是什么,是怎样工作的?
  18. 《菜鸟教程》丨2D骨骼动画工具DragonBones的使用教程
  19. Android Studio实现一个记账本项目
  20. 你认为的CISP这个证书是怎么样的

热门文章

  1. Python扫码登录保存和验证cookies值——微视篇(三)
  2. SwiftUI界面制作之List Navigation实现国画图文混排《潇湘卧游图》
  3. cv2 interpolate插值-align_corners
  4. 电子取证-----仿真技术
  5. Mongodb 按照时间进行分组统计查询
  6. 媒体聚焦:西电卡门——12月24日更新
  7. php中文网灭绝师太照片,灭绝师太照片欣赏
  8. 2021中国医疗机器人产业创新大会参会指南
  9. kernel中的日志打印
  10. 网页设计HTML遇到的问题,网页制作常遇到的问题集合