题目要求

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?

题目分析及思路

给定一个正整数范围,要求得到good number的个数。good number的定义是:对该数的各位数进行180度翻转,最后得到的数字与原数不同。这里,0,1,8翻转后还是本身,2,5,6,9翻转后可得不同的有效数字,剩余数字翻转则无效。可以先遍历这个范围的每一个数,并获得该数的各位数,最后只要确定各位数中没有3,4,7且有2,5,6,9即可确定该数为good number。

python代码

class Solution:

def rotatedDigits(self, N: int) -> int:

count = 0

for n in range(2,N+1):

digits = []

while n:

digit = n % 10

digits.append(digit)

n = n // 10

if not (set(digits) & set([3,4,7])) and (set(digits) & set([2,5,6,9])):

count += 1

return count

LeetCode 788 Rotated Digits 解题报告的更多相关文章

  1. 【LeetCode】788. Rotated Digits 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  2. #Leetcode# 788. Rotated Digits

    https://leetcode.com/problems/rotated-digits/ X is a good number if after rotating each digit indivi ...

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

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

  4. LeetCode 258 Add Digits 解题报告

    题目要求 Given a non-negative integer num, repeatedly add all its digits until the result has only one d ...

  5. 【LeetCode】738. Monotone Increasing Digits 解题报告(Python)

    [LeetCode]738. Monotone Increasing Digits 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu ...

  6. 【LeetCode】402. Remove K Digits 解题报告(Python)

    [LeetCode]402. Remove K Digits 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http: ...

  7. LeetCode 1 Two Sum 解题报告

    LeetCode 1 Two Sum 解题报告 偶然间听见leetcode这个平台,这里面题量也不是很多200多题,打算平时有空在研究生期间就刷完,跟跟多的练习算法的人进行交流思想,一定的ACM算法积 ...

  8. 【LeetCode】Permutations II 解题报告

    [题目] Given a collection of numbers that might contain duplicates, return all possible unique permuta ...

  9. 【Leetcode_easy】788. Rotated Digits

    problem 788. Rotated Digits solution1: class Solution { public: int rotatedDigits(int N) { ; ; i< ...

随机推荐

  1. Linux Crontab及使用salt进行管理

    一.引言: 最近无意之间看到salt有一个cron的模块,今天就在这里介绍linux crontab以及通过salt的cron对crontab的管理. 二.Linux crontab的介绍: cron ...

  2. PHP-问题处理验证码无法显示出来

    1.问题 今天重新安装了ubuntu,PHP,MySQL,Apache,到测试CMS项目时发生一个错误: 验证码无法显示出来. 2.解决: 2.1 使用 phpinfo检查: phpinfo(); 在 ...

  3. CentOS 6.5 x64下查看服务版本

    1.查看服务是否是64位 [root@Yimmei ~]# getconf LONG_BIT 642.查看服务器版本信息 [root@Yimmei ~]# lsb_release -a LSB Ver ...

  4. MUI框架的缩写输入

    html      上面--代表最小触发字符      下面--代表非必要完整触发字符 组件 触发字符 mDoctype(mui-dom结构) mdo ctype mBody(主体) mbo dy m ...

  5. ios调试-查看日志

    连上mac,然后打开“console.app”, 左侧设备里选这个设备.

  6. iOS 开发网络篇—监测网络状态

    iOS开发网络篇—监测网络状态 一.说明 在网络应用中,需要对用户设备的网络状态进行实时监控,有两个目的: (1)让用户了解自己的网络状态,防止一些误会(比如怪应用无能) (2)根据用户的网络状态进行 ...

  7. TCP断线重连

    struct sockaddr_in TempSadd; TempSadd.sin_family = AF_INET; TempSadd.sin_port = htons(m_ServerPort); ...

  8. 3D游戏图形引擎

    转自:http://www.cnblogs.com/live41/archive/2013/05/11/3072282.html CryEngine 3  http://www.crydev.net/ ...

  9. 告别GOPATH,快速使用 go mod(Golang包管理工具)

    https://studygolang.com/articles/17508?fr=sidebar 文中的wserver为module名,route为本地的包名,go.mod所在的目录名不一定非要和m ...

  10. 在vue中使用highcharts的仪表图等扩展

    仪表图(”solidgauge“)在highcharts中属于扩展,单独引入highcharts使用仪表图会报错,需要在你的组件中做一谢其他的引入: // 最主要是这里模块的引入 很坑 import ...