LeetCode 788 Rotated Digits 解题报告
题目要求
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 解题报告的更多相关文章
- 【LeetCode】788. Rotated Digits 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- #Leetcode# 788. Rotated Digits
https://leetcode.com/problems/rotated-digits/ X is a good number if after rotating each digit indivi ...
- LeetCode 788. Rotated Digits (旋转数字)
X is a good number if after rotating each digit individually by 180 degrees, we get a valid number t ...
- LeetCode 258 Add Digits 解题报告
题目要求 Given a non-negative integer num, repeatedly add all its digits until the result has only one d ...
- 【LeetCode】738. Monotone Increasing Digits 解题报告(Python)
[LeetCode]738. Monotone Increasing Digits 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu ...
- 【LeetCode】402. Remove K Digits 解题报告(Python)
[LeetCode]402. Remove K Digits 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http: ...
- LeetCode 1 Two Sum 解题报告
LeetCode 1 Two Sum 解题报告 偶然间听见leetcode这个平台,这里面题量也不是很多200多题,打算平时有空在研究生期间就刷完,跟跟多的练习算法的人进行交流思想,一定的ACM算法积 ...
- 【LeetCode】Permutations II 解题报告
[题目] Given a collection of numbers that might contain duplicates, return all possible unique permuta ...
- 【Leetcode_easy】788. Rotated Digits
problem 788. Rotated Digits solution1: class Solution { public: int rotatedDigits(int N) { ; ; i< ...
随机推荐
- MySQL技术内幕读书笔记(三)——文件
目录 文件 参数文件 日志文件 套接字文件 pid文件 表结构定义文件 INNODB存储引擎文件 文件 有以下类型文件 参数文件:告诉MYSQL实例启动时在哪里找到数据库文件,并且制定某些初始化参 ...
- Mac NVM 配置
1.NVM 简介 NVM(node version manager)是一个可以让你在同一台机器上安装和切换不同版本 node 的工具. GitHub 地址 2.NVM 环境配置 2.1 安装 NVM ...
- securecrt8.1破解版安装与注册机的使用方法
转自:https://blog.csdn.net/sun897827804/article/details/78532157?locationNum=9&fps=1 SecureCRT是一款用 ...
- 使用phpstorm进行PHP断点调试
PHP开发中都说一个会偷懒的程序员才是合格的程序员,在PHP开发中调试是必须要有的,可能要重复很多次的去调试,一次又一次,今天我们就来教教大家如何偷懒的,那么就来讲讲使用phpstorm进行偷懒吧! ...
- python3 利用正则获取网页中的想保存下来的内容
需要获取某个网页中表格部分中某个产品的成份 分析在html中成份的元素代码 <a href="/composition/4c3060178d1184935a48c4e51be4f63f ...
- static在类中的功能
有时候类需要它的一些成员与类本身直接相关,而不是与类的各个对象保持关联. 例如一个银行账户类可能需要一个数据成员来表示当前的利率.在此例中,我们希望利率与类关联,而非与类的每个对象关联.从实现效率上来 ...
- shell切分字符串到数组
shell切分字符串到数组 问题: 对于’aa,bb,cc,dd,ee’这样的字符串输出采用,分隔开的aa bb cc dd ee aa:bb is ok:/home/work按照":&qu ...
- WebRTC的视频解码原理简析
WebRTC的视频部分,包含采集.编解码(I420/VP8).加密.媒体文件.图像处理.显示.网络传输与流控(RTP/RTCP)等功能. 视频采集---video_capture: 源代码 ...
- Swagger UI 与SpringMVC的整合
关于 Swagger Swagger能成为最受欢迎的REST APIs文档生成工具之一,有以下几个原因: Swagger 可以生成一个具有互动性的API控制台,开发者可以用来快速学习和尝试API. S ...
- 基于【CentOS-7+ Ambari 2.7.0 + HDP 3.0】搭建HAWQ数据仓库03 —— 安装HAWQ 2.3.0.0
一. HAWQ2.3.0环境准备[全部主机节点]: 1, vim /etc/sysctl.conf,编辑如下内容: kernel.shmmax= kernel.shmmni= kernel.shmal ...