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.
[暴力解法]:
时间分析:
空间分析:
[优化后]:
时间分析:
空间分析:
[奇葩输出条件]:
[奇葩corner case]:
[思维问题]:
[一句话思路]:
至少包括一个2/5/6/9,不能有3/4/7
[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):
[画图]:
[一刷]:
[二刷]:
[三刷]:
[四刷]:
[五刷]:
[五分钟肉眼debug的结果]:
[总结]:
滥竽充数的一道题
[复杂度]:Time complexity: O(n) Space complexity: O(1)
[英文数据结构或算法,为什么不用别的数据结构或算法]:
[关键模板化代码]:
[其他解法]:
[Follow Up]:
[LC给出的题目变变变]:
[代码风格] :
class Solution {
public int rotatedDigits(int N) {
//cc
if (N == 0) {
return 0;
}
//ini
int count = 0;
//for loop
for (int i = 1; i <= N; i++) {
if (isValid(i)) {
count++;
}
}
//return
return count;
} public boolean isValid(int i) {
boolean trueState = false; while (i != 0) {
if (i % 10 == 2) trueState = true;
if (i % 10 == 5) trueState = true;
if (i % 10 == 6) trueState = true;
if (i % 10 == 9) trueState = true;
if (i % 10 == 3) return false;
if (i % 10 == 4) return false;
if (i % 10 == 7) return false;
i = i / 10;
} //return
return trueState;
}
}
788. Rotated Digits 旋转数字的更多相关文章
- 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] Rotated Digits 旋转数字
X is a good number if after rotating each digit individually by 180 degrees, we get a valid number t ...
- Leetcode788.Rotated Digits旋转数字
我们称一个数 X 为好数, 如果它的每位数字逐个地被旋转 180 度后,我们仍可以得到一个有效的,且和 X 不同的数.要求每位数字都要被旋转. 如果一个数的每位数字被旋转以后仍然还是一个数字, 则这个 ...
- 【Leetcode_easy】788. Rotated Digits
problem 788. Rotated Digits solution1: class Solution { public: int rotatedDigits(int N) { ; ; i< ...
- 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 ...
- 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 788. Rotated Digits
X is a good number if after rotating each digit individually by 180 degrees, we get a valid number t ...
- 【LeetCode】788. Rotated Digits 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
随机推荐
- 瀑布流下滑 发送ajax
<!DOCTYPE=html> <html> <head> <meta charset="UTF-8"> ...
- CF311B Cats Transport
题意 Zxr960115 is owner of a large farm. He feeds m cute cats and employs p feeders. There's a straigh ...
- centos6.5 安装sftp
1.创建sftp组 : groupadd sftp 2.创建一个sftp用户,用户名为andy : useradd -g sftp -s /bin/false andy 3.修改密码: pas ...
- 笔记:Why don't you pull up a chair and give this lifestyle a try?
Why don't you pull up a chair and give this lifestyle a try? Why don't you pull up a chair and give ...
- float型数据与字节数组的转化
float型数据与字节数组的转化 字节(float)浮点数为例. 一.C语言 转化常见的方法有: 1.强制指针类型转换. [html] view plain copy //转换float数据到字节数组 ...
- MyBatis 工具 pndao - 自动写 SQL
pndao的原理并不复杂,是基于MyBatis的方法命名约定来生成SQL,并且写入MyBatis需要的XML. 写之前会判断是否已经存在XML或者注解,如果已经存在则略过此方法,所以无论是注解还是XM ...
- mysql表的增删改查
一.表介绍 表相当于文件,表中的一条记录就相当于文件的一行内容,不同的是,表中的一条记录有对应的标题,称为表的字段 id,name,qq,age称为字段,其余的,一行内容称为一条记录 二.创建表 cr ...
- Protege4.3使用入门(一)
1.下载 下载地址http://protege.stanford.edu/download/protege/4.3/installanywhere/Web_Installers/,目前版本信息Prot ...
- python学习——练习题(3)
""" 题目:一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少? """ import math d ...
- Iterator(迭代器)的一般用法 (转)
迭代器(Iterator) 迭代器是一种设计模式,它是一个对象,它可以遍历并选择序列中的对象,而开发人员不需要了解该序列的底层结构.迭代器通常被称为“轻量级”对象,因为创建它的代价小. Java中的I ...