题目描述:

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.
class Solution {
public:bool confusingNumber(int N) {int M=N;int n=0;while(M>0){int x=M%10;n*=10;M/=10;if(x==0||x==1||x==8) n+=x;else if(x==6) n+=9;else if(x==9) n+=6;else return false;}return n!=N;}
};

LeetCode #1056. Confusing Number相关推荐

  1. LeetCode 1056. 易混淆数(哈希)

    文章目录 1. 题目 2. 解题 1. 题目 给定一个数字 N,当它满足以下条件的时候返回 true: 原数字旋转 180° 以后可以得到新的数字. 如 0, 1, 6, 8, 9 旋转 180° 以 ...

  2. LeetCode:Largest Number - 求整型数组中各元素可拼合成的最大数字

    2019独角兽企业重金招聘Python工程师标准>>> 1.题目名称 Largest Number(求整型数组中各元素可拼合成的最大数字) 2.题目地址 https://leetco ...

  3. 【整数转字符串】LeetCode 9. Palindrome Number

    LeetCode 9. Palindrome Number Solution1: 不利用字符串 class Solution { public:bool isPalindrome(int x) {if ...

  4. 【To Do! 重点 正则表达式】LeetCode 65. Valid Number

    LeetCode 65. Valid Number 本博客转载自:[1]http://www.cnblogs.com/yuzhangcmu/p/4060348.html [2]https://blog ...

  5. 【回文串2】LeetCode 9. Palindrome Number

    LeetCode 9. Palindrome Number Solution1:我的答案 思路一:转化为字符串 class Solution { public:bool isPalindrome(in ...

  6. 【?异或】LeetCode 260. Single Number III

    LeetCode 260. Single Number III Solution1: 博客转载自:http://www.cnblogs.com/grandyang/p/4741122.html 这道题 ...

  7. 【异或】LeetCode 137. Single Number II

    LeetCode 137. Single Number II Solution1:不会做,抄的 博客转载自:http://www.cnblogs.com/grandyang/p/4263927.htm ...

  8. 【异或】LeetCode 136. Single Number

    LeetCode 136. Single Number Solution1:我的答案 还好异或的性质没记错,还好,还好 class Solution { public:int singleNumber ...

  9. [LeetCode]179. Largest Number

    [LeetCode]179. Largest Number 题目描述 解题思路 求最大的数,在数组中对于每一位数字数值越大应当越靠前,如:9 > 5,所以9应该在5之前 需要考虑的是对于不同位数 ...

  10. LeetCode 871. Minimum Number of Refueling Stops 最少加油次数

    LeetCode 871. Minimum Number of Refueling Stops 本题是LeetCode 871题,最少加油次数. 题目描述 A car travels from a s ...

最新文章

  1. 大规模服务设计部署经验谈
  2. Git_Eclipse:[3]Git初始化工程
  3. 每次执行java命令 都要source_跟着平台混了四年,现在要单飞了!
  4. 洛谷——P1549 棋盘问题(2)
  5. python random randint_python中random.randint(1,100)随机数中包不包括1和100
  6. WriteableBitmap process summary
  7. easyUi load方法重新加载表单的数据
  8. go token验证_GitHub - goflyfox/gtoken: 基于gf框架的token插件,通过服务端验证方式实现token认证;...
  9. Windows server 2003 下载
  10. 室内设计——KTV室内设计(包含预览图jpg和.psd文件)
  11. java coap_CoAP协议-以Californium(Java)为例的CoAP初步实现
  12. 四川取消英语计算机考试,2020年起,四川将不再承接全国英语等级考试,已有多省份停考!...
  13. java中图片排版_Java实现第八届蓝桥杯图形排版
  14. OpenGL(预备篇3)---OpenGL编程环境配置 vs2017篇---GLM---(自己动手系列)
  15. 神经网络与傅立叶变换到底有没有关系?
  16. 【020期】面试官问:Java 遍历 Map 集合有几种方式?效率如何?
  17. Stale branches 设置_手机资讯:iPhone 如何设置来电闪光灯苹果手机 LED 灯来电提醒设置教程...
  18. Java,配置Java环境
  19. Kali Linux(2021.2)系统 安装中文输入法
  20. web安全之信息刺探防范(下)

热门文章

  1. web端接入QQ第三方登陆获取本地QQ登陆信息流程
  2. 应用html的DIV+CSS制作牛顿摆
  3. 安装Aras Innovator12 sp9全过程
  4. 如何用电脑画平面坐标图_如何画坐标图?
  5. 计算机表格如何求和,excel表格怎么求和? excel自动求和的三种方法
  6. IE浏览器设置UserAgent
  7. Shiro的Subject对象详解
  8. 访问项目,页面打开太慢解决方式
  9. 获取域名服务器信息吗,获取域名的WHOIS信息
  10. (一)线段树入门--补充与其他模板