788. 旋转数字

788. Rotated Digits

题目描述

我们称一个数 X 为好数, 如果它的每位数字逐个地被旋转 180 度后,我们仍可以得到一个有效的,且和 X 不同的数。要求每位数字都要被旋转。

如果一个数的每位数字被旋转以后仍然还是一个数字, 则这个数是有效的。0, 1, 和 8 被旋转后仍然是它们自己;2 和 5 可以互相旋转成对方;6 和 9 同理,除了这些以外其他的数字旋转以后都不再是有效的数字。

现在我们有一个正整数 N, 计算从 1 到 N 中有多少个数 X 是好数?

每日一算法2019/6/8Day 36LeetCode788. Rotated Digits

示例:

输入: 10
输出: 4
解释:
在[1, 10]中有四个好数: 2, 5, 6, 9。
注意 1 和 10 不是好数, 因为他们在旋转之后不变。

注意:

  • N 的取值范围是 [1, 10000]。

Java 实现

class Solution {
public int rotatedDigits(int N) {
int res = 0;
for (int i = 1; i <= N; i++) {
if (isGood(i)) {
res++;
}
}
return res;
} public boolean isGood(int num) {
boolean flag = false;
int c;
while (num != 0) {
c = num % 10;
num = num / 10;
if (c == 3 || c == 4 || c == 7) {
return false;
}
if (c == 2 || c == 5 || c == 6 || c == 9) {
flag = true;
}
}
return flag;
}
}

参考资料

LeetCode 788. 旋转数字(Rotated Digits) 36的更多相关文章

  1. Java实现 LeetCode 788 旋转数字(暴力)

    788. 旋转数字 我们称一个数 X 为好数, 如果它的每位数字逐个地被旋转 180 度后,我们仍可以得到一个有效的,且和 X 不同的数.要求每位数字都要被旋转. 如果一个数的每位数字被旋转以后仍然还 ...

  2. [Swift]LeetCode788. 旋转数字 | Rotated Digits

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

  3. [LeetCode] 81. Search in Rotated Sorted Array II 在旋转有序数组中搜索 II

    Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? Would this ...

  4. [leetcode]81. Search in Rotated Sorted Array II旋转过有序数组里找目标值II(有重)

    This is a follow up problem to Search in Rotated Sorted Array, where nums may contain duplicates. 思路 ...

  5. 【Leetcode_easy】788. Rotated Digits

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

  6. [LeetCode] 033. Search in Rotated Sorted Array (Hard) (C++)

    指数:[LeetCode] Leetcode 解决问题的指数 (C++/Java/Python/Sql) Github: https://github.com/illuz/leetcode 033. ...

  7. Leetcode Find Minimum in Rotated Sorted Array 题解

    Leetcode Find Minimum in Rotated Sorted Array 题目大意: 对一个有序数组翻转, 就是随机取前K个数,移动到数组的后面,然后让你找出最小的那个数.注意,K有 ...

  8. Java for LeetCode 081 Search in Rotated Sorted Array II

    Follow up for "Search in Rotated Sorted Array": What if duplicates are allowed? Would this ...

  9. 前端与算法 leetcode 189. 旋转数组

    目录 # 前端与算法 leetcode 189. 旋转数组 题目描述 概要 提示 解析 算法 # 前端与算法 leetcode 189. 旋转数组 题目描述 189. 旋转数组 概要 把他当做一到简单 ...

随机推荐

  1. janusgraph-遍历图的语言

    精确查询 语句含义 测试语句 执行时间 查询顶点标签为FALV的顶点数量 g.V().hasLabel('FALV').count() 2400s 查询顶点属性中id为19012201 clockWi ...

  2. [Luogu 2386]放苹果

    Description 题库链接 把 \(n\) 个同样的苹果放在 \(m\) 个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分发.多测,数据组数 \(t\). \(1\leq m,n\le ...

  3. selenium原理解析

    相信很多测试小伙伴儿都听过或者使用过web自动化selenium,那您有没有研究过selenium的原理呢?为什么要使用webdriver.exe,webdriver.exe是干啥用的?seleniu ...

  4. Python微信操控(itchat)

    itchat是一个开源的微信个人号接口,使用python调用微信从未如此简单. 开源地址 https://github.com/littlecodersh/ItChat 文档: https://itc ...

  5. 基于思岚A1激光雷达+OpenGL+VS2017的Ramer-Douglas-Peucker算法的实现

    时隔两年 又借到了之前的那个激光雷达,最老版本的思岚A1,甚至不支持新的固件,并且转接板也不见了,看了下淘宝店卖¥80,但是官方提供了一个基于STM32的实现方式,于是我估摸着这个转接板只是一个普通的 ...

  6. BZOJ 1477: 青蛙的约会

    二次联通门 : BZOJ 1477: 青蛙的约会 /* BZOJ 1477: 青蛙的约会 扩展欧几里得 列出方程, 判断一下 */ #include <iostream> #include ...

  7. tensorflow手写数字识别(有注释)

    import tensorflow as tf import numpy as np # const = tf.constant(2.0, name='const') # b = tf.placeho ...

  8. Jedis:Exception in thread "main" java.lang.VerifyError: Bad type on operand stack

    Exception in thread "main" java.lang.VerifyError: Bad type on operand stackException Detai ...

  9. AC自动机入门经典题目(两种表达方式)

    Keywords Search 指针方式: /* Keywords Search */ # include <iostream> # include <stdio.h> # i ...

  10. go语言new和make

    1.new func new(Type) *Type 内建函数,内建函数 new 用来分配内存,它的第一个参数是一个类型,它的返回值是一个指向新分配类型默认值的指针! 2.make func make ...