LeetCode #1056. 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:
0 <= N <= 10^9
- After the rotation we can ignore leading zeros, for example if after rotation we have
0008
then this number is considered as just8
.
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相关推荐
- LeetCode 1056. 易混淆数(哈希)
文章目录 1. 题目 2. 解题 1. 题目 给定一个数字 N,当它满足以下条件的时候返回 true: 原数字旋转 180° 以后可以得到新的数字. 如 0, 1, 6, 8, 9 旋转 180° 以 ...
- LeetCode:Largest Number - 求整型数组中各元素可拼合成的最大数字
2019独角兽企业重金招聘Python工程师标准>>> 1.题目名称 Largest Number(求整型数组中各元素可拼合成的最大数字) 2.题目地址 https://leetco ...
- 【整数转字符串】LeetCode 9. Palindrome Number
LeetCode 9. Palindrome Number Solution1: 不利用字符串 class Solution { public:bool isPalindrome(int x) {if ...
- 【To Do! 重点 正则表达式】LeetCode 65. Valid Number
LeetCode 65. Valid Number 本博客转载自:[1]http://www.cnblogs.com/yuzhangcmu/p/4060348.html [2]https://blog ...
- 【回文串2】LeetCode 9. Palindrome Number
LeetCode 9. Palindrome Number Solution1:我的答案 思路一:转化为字符串 class Solution { public:bool isPalindrome(in ...
- 【?异或】LeetCode 260. Single Number III
LeetCode 260. Single Number III Solution1: 博客转载自:http://www.cnblogs.com/grandyang/p/4741122.html 这道题 ...
- 【异或】LeetCode 137. Single Number II
LeetCode 137. Single Number II Solution1:不会做,抄的 博客转载自:http://www.cnblogs.com/grandyang/p/4263927.htm ...
- 【异或】LeetCode 136. Single Number
LeetCode 136. Single Number Solution1:我的答案 还好异或的性质没记错,还好,还好 class Solution { public:int singleNumber ...
- [LeetCode]179. Largest Number
[LeetCode]179. Largest Number 题目描述 解题思路 求最大的数,在数组中对于每一位数字数值越大应当越靠前,如:9 > 5,所以9应该在5之前 需要考虑的是对于不同位数 ...
- LeetCode 871. Minimum Number of Refueling Stops 最少加油次数
LeetCode 871. Minimum Number of Refueling Stops 本题是LeetCode 871题,最少加油次数. 题目描述 A car travels from a s ...
最新文章
- 大规模服务设计部署经验谈
- Git_Eclipse:[3]Git初始化工程
- 每次执行java命令 都要source_跟着平台混了四年,现在要单飞了!
- 洛谷——P1549 棋盘问题(2)
- python random randint_python中random.randint(1,100)随机数中包不包括1和100
- WriteableBitmap process summary
- easyUi load方法重新加载表单的数据
- go token验证_GitHub - goflyfox/gtoken: 基于gf框架的token插件,通过服务端验证方式实现token认证;...
- Windows server 2003 下载
- 室内设计——KTV室内设计(包含预览图jpg和.psd文件)
- java coap_CoAP协议-以Californium(Java)为例的CoAP初步实现
- 四川取消英语计算机考试,2020年起,四川将不再承接全国英语等级考试,已有多省份停考!...
- java中图片排版_Java实现第八届蓝桥杯图形排版
- OpenGL(预备篇3)---OpenGL编程环境配置 vs2017篇---GLM---(自己动手系列)
- 神经网络与傅立叶变换到底有没有关系?
- 【020期】面试官问:Java 遍历 Map 集合有几种方式?效率如何?
- Stale branches 设置_手机资讯:iPhone 如何设置来电闪光灯苹果手机 LED 灯来电提醒设置教程...
- Java,配置Java环境
- Kali Linux(2021.2)系统 安装中文输入法
- web安全之信息刺探防范(下)