[LeetCode&Python] Problem 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?
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]
.
class Solution(object):
def rotatedDigits(self, N):
"""
:type N: int
:rtype: int
"""
ans=0 for i in range(N):
l=str(i+1)
if '3' not in l and '4' not in l and '7' not in l:
if '1' in l or '0' in l or '8' in l:
if '2' in l or '5' in l or '6' in l or '9' in l:
ans+=1
else:
ans+=1 return ans
[LeetCode&Python] Problem 788. Rotated Digits的更多相关文章
- [LeetCode&Python] Problem 258. Add Digits
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. ...
- 【Leetcode_easy】788. Rotated Digits
problem 788. Rotated Digits solution1: class Solution { public: int rotatedDigits(int N) { ; ; i< ...
- 【LeetCode】788. Rotated Digits 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- LeetCode 788 Rotated Digits 解题报告
题目要求 X is a good number if after rotating each digit individually by 180 degrees, we get a valid num ...
- #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 ...
- 788. Rotated Digits
X is a good number if after rotating each digit individually by 180 degrees, we get a valid number t ...
- [LeetCode&Python] Problem 415. Add Strings
Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2 ...
- [LeetCode&Python] Problem 202. Happy Number
Write an algorithm to determine if a number is "happy". A happy number is a number defined ...
随机推荐
- redis的文件事件
redis的文件事件:即与io相关的事件. /* File event structure */ typedef struct aeFileEvent { int mask; /* one of AE ...
- 解决win10打开组策略弹出管理模板对话框问题
今天win10企业版更新完系统,打开组策略编辑器时弹出管理模板对话框问题 1.问题描述 打开组策略编辑器时弹出管理模板对话框问题 2.解决方法 1)window+x 打开命令提示符(管理员) 2)输入 ...
- 微信和支付宝支付模式详解及实现(.Net标准库)
支付基本上是很多产品都必须的一个模块,大家最熟悉的应该就是微信和支付宝支付了,不过更多的可能还是停留在直接sdk的调用上,甚至和业务系统高度耦合,网上也存在各种解决方案,但大多形式各异,东拼西凑而成. ...
- 写一个xml文件到磁盘的方法
/** * 往磁盘上写一个xml文件 * * <?xml version="1.0" encoding="UTF-8" standalone=" ...
- MeshLab 编译
1.需要以下: MeshLab 1.3.3 下载地址 http://sourceforge.net/projects/meshlab/files/meshlab Win7 X64 Visual ...
- shell脚本总结
1.变量 A: 定义变量A=1,只会对自己所在的shell进程有效 B: 定义变量export B=1,会对自己所在的shell进程及其子进程生效 C: 在script.sh脚本中定义的变量,在当前 ...
- ubuntu多显示器单触摸屏校准
多显示器单触摸屏屏幕校准 0.触摸屏重定向 sudo xinput map-to-output 13 DP1 #将触摸屏映射到指定的显示器 其中:13为触摸屏设备id,可通过 xinput命令查看 ...
- Java学习笔记整理第一章 java基本数据类型、修饰符、运算符
Java关键字: Java关键字是电脑语言里事先定义的,有特别意义的标识符,有时又叫保留字,还有特别意义的变量.Java的关键字对Java的编译器有特殊的意义,他们用来表示一种数据类型,或者表示程序的 ...
- fk makefile文件的一些问题
除了要按具神说的makefile修改之外,还发现了另外一个问题: 不然就改成SACLIB=-L/usr/local/sac/lib
- Java读取键盘输入
三种方法分别如下: 方法一:从控制台接收一个字符,然后将其打印出来 import java.io.*; public static void main(String [] args) throws I ...