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的更多相关文章

  1. [LeetCode&Python] Problem 258. Add Digits

    Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. ...

  2. 【Leetcode_easy】788. Rotated Digits

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

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

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

  4. LeetCode 788 Rotated Digits 解题报告

    题目要求 X is a good number if after rotating each digit individually by 180 degrees, we get a valid num ...

  5. #Leetcode# 788. Rotated Digits

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

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

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

  7. 788. Rotated Digits

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

  8. [LeetCode&Python] Problem 415. Add Strings

    Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2 ...

  9. [LeetCode&Python] Problem 202. Happy Number

    Write an algorithm to determine if a number is "happy". A happy number is a number defined ...

随机推荐

  1. virtualenv 运行python 解决依赖冲突问题 尤其是django那种蛋疼的版本问题

    Create a python virtual environment and install python dependencies. cd evalai virtualenv venv sourc ...

  2. Spring事务的开启方式

    1.通过注解方式@Transactional @Transactional(rollbackForClassName = { "Exception", "RuntimeE ...

  3. linux下stat命令详解

    在linux系统下,使用stat(显示inode信息)命令可以查看一个文件的某些信息,我们先来尝试一下.  简单的介绍一下stat命令显示出来的文件其他信息: - File:显示文件名 - Size: ...

  4. Win10系列:UWP界面布局进阶1

    全新的Windows 10 操作系统支持多种视图模式,用户可以根据需要选择不同的视图模式显示应用.当用户同时浏览或操作多个应用程序时,可以将应用视图调整为辅屏视图或填充视图,这样在一个屏幕中可以同时对 ...

  5. 微信授权(Net Mvc)

    项目结构 WeiXinController.cs using System; using System.Collections.Generic; using System.Linq; using Sy ...

  6. Unity中UI界面颤抖解决方法

    将Render Mode中属性改为Screen Space - Camera 摄像机挂在Canvas属性下会出现UI界面颤抖的效果. UI界面颤抖解决方式:将Render Mode中属性改为Scree ...

  7. js中 offset /client /scroll总结

    offset家族(只能读取,不能操作): offsetLeft:元素的边框的外边缘距离与已定位的父容器(offsetparent)的左边距离(就是子元素左边框到父元素左边框的距离). offsetTo ...

  8. RabbitMQ direct类型的Exchange

    就目前来说,Exchange是与消息发送端有关的,因为它可以指定将消息发送到哪个或哪些队列中. 本篇文章介绍的direct类型就是指定将消息定向发送到哪个队列中. direct,顾名思义,就是直接的意 ...

  9. 前端之Bootstrap框架

    一.Bootstrap介绍 Bootstrap是Twitter开源的基于HTML.CSS.JavaScript的前端框架. 它是为实现快速开发Web应用程序而设计的一套前端工具包. 它支持响应式布局, ...

  10. בוא--来吧--IPA--希伯来语

    灰常好听的希伯来语歌曲, Rita唱得真好.