[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 ...
随机推荐
- Django之路由分配系统
前言: Django大致工作流程 1.客户端发送请求(get/post)经过web服务器.Django中间件. 到达路由分配系统 2.路由分配系统根据提取 request中携带的的url路径(path ...
- VIM编辑配置文件基本操作
vim /etc/apt/sources.list 按insert键进入编辑状态 编辑完成以后按ESC退出编辑状态 输入 ":"进入命令状态,常用命令: 1.W:write ,写 ...
- mongdb使用
下载mongodb数据库 https://www.mongodb.com/ 根据自己的电脑系统下载相应的版本 安装并且打开你下载的数据库 打开数据库bin文件夹: cd soft/ ...
- 认识微软Visual Studio Tools for AI
认识微软Visual Studio Tools for AI 微软已经发布了其 Visual Studio Tools for AI 的测试版本,这是微软 Visual Studio 2017 I ...
- PHP开发者的Linux学习之路
谈起一个高效动态网站的构建,那就不得不提到LAMP,即Linux操作系统.Apache网络服务器.Mysql数据库.Perl.PHP或Python编程语言等开源产品所组成的网站架构框架,其最大的优势是 ...
- Unity运行错误代码处理
1.Unity在运行时出现如图错误,但不影响运行效果展示. 2.错误原因:代码不规范. 3.检查代码,查看变量是否定义正确.
- log4j不输出日志的解决方案
参考:http://blog.csdn.net/qq994406030/article/details/53433159 主要是log4j.properties log权限和log输出方式没配好.
- csv,json格式数据的读写
#!python3 # -*- coding:utf-8 -*- #CSV stands for "comma-separated values",and CSV files ar ...
- 源码学习:一个express().get方法的加载与调用
刚刚接触express,它的中间件确实把我搞得头晕.get的回调中要不要加next?不加载还会执行下一个中间件么?给get指定'/'路径是不是所有以'/'开头的访问在没有确切匹配时都能执行?use件又 ...
- 2.18 C++类与static关键字
参考:http://www.weixueyuan.net/view/6349.html 总结: 类中的成员变量或成员函数一旦与static关键字相结合,则该成员变量或成员函数就是属于类的,而不是再是属 ...