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< ...
随机推荐
- 免费ss账号网站
下面网址按排序顺序优先使用,数字越小优先级越高 1,https://io.freess.today/ 2,https://free-ss.site/ 3,https://ss.freess.org/ ...
- Google protobuf解析消息逻辑的版本问题
在分析caffe2源码的过程中,由于caffe2使用protobuf作为网络结构和网络参数序列化和反序列化的机制,想在反序列化之前进行加解密处理,这是反向protouf其实有两个版本的实现来进行消息的 ...
- Atitit 文员招募规范 attilax总结
Atitit 文员招募规范 attilax总结 1. 概念 2 2. 文员招募范文 2 3. 重大意义 3 3.1. 第一层 文章撰写 能力 3 3.2. 第二次 文档管理能力 文档索引 检索查找 ...
- vim几种常用的插入模式
我们来看一下cw这个命令,它是从光标处替换到后一个单词的结尾.比如说我的光标如图: 我的namespace写错了,后面的都对,就可以用cw命令,
- 【宣讲】德州科技职业学院宣讲关于IT领域趋势分析
12月25日,AICODER马伦老师受德州科技职业学院校领导的邀请,到德州科技职业学院青岛校区洽谈新型的校区合作,创新现有的职业教育的传统模式的束缚,探索新型的职业教育直接跟企业实习实战结合的新型职业 ...
- 我对CopyOnWrite的思考
CopyOnWrite 后文中表述为 COW CopyOnWrite容器即写的时候复制一个新的容器进行写:通俗的理解是当我们往一个容器添加元素的时候,不直接往当前容器添加,而是先将当前容器进行Copy ...
- [转]html5: postMessage解决跨域和跨页面通信的问题
[转]html5: postMessage解决跨域和跨页面通信的问题 平时做web开发的时候关于消息传递,除了客户端与服务器传值,还有几个经常会遇到的问题: 多窗口之间消息传递(newWin = wi ...
- 复制id_rsa命令
pbcopy < ~/.ssh/id_rsa.pub https://aliasan-conf.taijiankong.cn/duotai/2T7b253i8.pac
- datatable to List<T>带缓存
public class DataHelper { //datarow 转换的类型缓存 private static MemoryCache modelCash = MemoryCache.Defau ...
- chrome自动填表会遮挡input中背景图的问题解决方法
在做某项目登录界面时,发现用户密码框在Chrome自动填充时,input中的背景框会被遮住.网上也搜了一下,没有一个有效的解决方法. 来看csdn的登录界面,也有这个问题. 后来在浏览网页时,无意中发 ...