X is a good number if after rotating each digit individually by 180 degrees, we get a valid number that is different from X.  Each digit must be rotated - we cannot choose to leave it alone.

A number is valid if each digit remains a digit after rotation. 0, 1, and 8 rotate to themselves; 2 and 5 rotate to each other; 6 and 9 rotate to each other, and the rest of the numbers do not rotate to any other number and become invalid.

Now given a positive number N, how many numbers X from 1 to N are good?

Example:
Input: 10
Output: 4
Explanation:
There are four good numbers in the range [1, 10] : 2, 5, 6, 9.
Note that 1 and 10 are not good numbers, since they remain unchanged after rotating.

Note:

  • N  will be in range [1, 10000].

这道题定义了一种好数字,就是把每位上的数字自身翻转一下,能得到一个不同的数字。翻转规则定义为,0,1,和8翻转后还为其本身,2和5,6和9可以互相翻转。然后给了一个数字N,问 [1, N] 区间内共有多少个这样的好数字。这道题大家踩

[LeetCode] Rotated Digits 旋转数字的更多相关文章

  1. LeetCode 788. Rotated Digits (旋转数字)

    X is a good number if after rotating each digit individually by 180 degrees, we get a valid number t ...

  2. Leetcode788.Rotated Digits旋转数字

    我们称一个数 X 为好数, 如果它的每位数字逐个地被旋转 180 度后,我们仍可以得到一个有效的,且和 X 不同的数.要求每位数字都要被旋转. 如果一个数的每位数字被旋转以后仍然还是一个数字, 则这个 ...

  3. 788. Rotated Digits 旋转数字

    [抄题]: X is a good number if after rotating each digit individually by 180 degrees, we get a valid nu ...

  4. [LeetCode] Add Digits 加数字

    Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. ...

  5. leetCode题解之旋转数字

    1.题目描述 X is a good number if after rotating each digit individually by 180 degrees, we get a valid n ...

  6. Leetcode: Rotated Digits

    X is a good number if after rotating each digit individually by 180 degrees, we get a valid number t ...

  7. LeetCode 788. 旋转数字(Rotated Digits) 36

    788. 旋转数字 788. Rotated Digits 题目描述 我们称一个数 X 为好数, 如果它的每位数字逐个地被旋转 180 度后,我们仍可以得到一个有效的,且和 X 不同的数.要求每位数字 ...

  8. Java实现 LeetCode 788 旋转数字(暴力)

    788. 旋转数字 我们称一个数 X 为好数, 如果它的每位数字逐个地被旋转 180 度后,我们仍可以得到一个有效的,且和 X 不同的数.要求每位数字都要被旋转. 如果一个数的每位数字被旋转以后仍然还 ...

  9. LeetCode 81——搜索旋转排序数组 II

    1. 题目 2. 解答 2.1. 方法一 基于 LeetCode 33--搜索旋转排序数组 中的方法二. 当 nums[mid] = nums[right] 时,比如 [1, 1, 2, 1, 1], ...

随机推荐

  1. 用 Mathematica 获取图片的 RGB 三基色

    ColorConvert[*, "RGB"] // InputForm 其中 * 表示你把你的图片拖入 Mathematica 中.

  2. 淘宝网站上的 HTTP 缓存问题两则

    在阅读本文前推荐你先阅读我的前两篇文章< 扼杀 304,Cache-Control: immutable>和<关于缓存和 Chrome 的“新版刷新”>:下面要说的两个问题是在 ...

  3. docker学习-----docker可视化portainer

    docker的可视化操作界面portainer 1.创建一个挂载区          docker volume create portainer_data 2.安装( docker run -d - ...

  4. JAVA进阶5

    间歇性混吃等死,持续性踌躇满志系列-------------第5天 1.IDEA常用快捷键 2.简单方法的使用 package cn.intcast.day05.demo01; public clas ...

  5. AWK如何打印从某一列到最后一列的内容

    awk -F " "  '{for (i=4;i<=NF;i++)printf("%s ", $i);print ""}' file

  6. Windows密钥容器和证书的关系

    其实CSP主要是对容器里的密钥对操作的,和证书关系不大. 容器里的密钥对有两种类型:一种是AT_KEYEXCHANGE,表示加密的密钥对,一种是AT_SIGNATURE表示签名的密钥对. 由于美国的出 ...

  7. MySQL -- 关闭 binlog

    LNMP一键安装包安装的MySQL默认是开启了日志文件的,如果数据操作比较频繁就会产生大量的日志,在/usr/local/mysql /var/下面产生mysql-bin.0000* 类似的文件,而且 ...

  8. C# 微信开发-----微信会员卡(二)

    主要说说如何使用微信的激活会员卡 如图: 点击激活会员卡时,要跳转到如下的图片: 要实现这个功能,首先我们在创建会员卡后就操作如下代码 #region 添加激活时的自定义字段 string custo ...

  9. RDay1-Problem 1 A

    题目描述 给定一个长度为n的正整数序列a[i],计算出有多少个i<j的数对,a[i]+a[j]为二的次幂,也就是说存在一个正整数x满足a[i]+a[j]==2^x. 输入 输入文件A.in. 第 ...

  10. SQL insert

    INSERT INTO 插入语句 INSERT INTO语句用于在表中插入新记录. 可以用两种方式编写INSERT INTO语句. 第一种方法指定列名和要插入的值: 1 2 INSERT INTO t ...