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. fetch 的控制器和观察者

    因为受 cancelable promise 的拖延,fetch 一直没有传统的 XHR 所拥有的 abort() 和 onprogress 功能,去年年底 cancelable promise 草案 ...

  2. 🍓JavaScript 对象原型链继承的弊端 🍓

  3. pyhon 模块 IP/端口 扫描

    用到了python-nmap模块(注意是 python-nmap模块 不是nmap模块 且不要安装nmap模块!!!!) windows 中还需要下载一个 nmap 软件: 下载地址: https:/ ...

  4. linux tomcat单机部署多应用

    1.修改/etc/profile 增加tomcat环境变量

  5. Python的真和假

    python和其他编程语言一样,,,0是假,非0是真,,python 一切皆对象,真假是每个对象的属性.像数据结构,,空的数据结构是False. eg: "spam" True & ...

  6. Fork别人的代码 原作者更新后如何同步

    给主题的fork加一个remote 给 fork 配置一个 remote 使用 git remote -v 查看远程状态 ➜ next git:(master) git remote -v origi ...

  7. Lua中的闭包

    [什么是闭包?] 闭包在Lua中是一个非常重要的概念,闭包是由函数和与其相关的引用环境组合而成的实体.我们再来看一段代码: function newCounter() return function ...

  8. 【easy】118.119.杨辉三角

    这题必会啊!!! 第一题118. class Solution { public: vector<vector<int>> generate(int numRows) { ve ...

  9. 安装anaconda和python3.7环境

    安装anaconda和python3.7 安装matplotlib报错(参考https://github.com/conda/conda/issues/6007)# 设置源为清华conda confi ...

  10. 关于button去掉自带阴影效果的方法

    在button的属性设置里加上: style=”?android:attr/borderlessButtonStyle” 即: <Button android:layout_width=&quo ...