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 ...
随机推荐
- (三)java程序的编译和执行
编写java程序 eg class Demo { /* * 程序运行的入口 */ public static void main(String[] args) { System.out.println ...
- self = [super init]
Objective-C的推荐init方法写法如下: - (id) init { if(self = [super init]) { //为子类增加属性进行初始化 } return self; } 返回 ...
- jfrog artifactory jenkins pipeline 集成
1. 预备环境 artifactory ( 开源版本 ) maven jenkins jenkins artifactory plugin (在插件管理安装即可) 2. 配置artifactory ...
- keycloak && docker安装 &&spring boot 集成使用
1. 基础依赖 a. docker mysql b. dokcer keycloak-mysql 2. 安装 mysql (注意实际使用最好使用本地数据卷) docker run --na ...
- FastAdmin 出现慢的问题 (DB host)
FastAdmin 出现慢的问题 用户反馈断网后 FastAdmin 后台变慢. 而且是很多同事出现一样的现象. 查看了 runtime / log 里的日志,发现 DB 时间超过 20s. 经过群里 ...
- ubuntu 设置固定DNS
1.打开 xxx@ubuntu:~$ sudo vim /etc/resolvconf/resolv.conf.d/base 2.输入以下DNS,保存退出. nameserver 8.8.8.8 na ...
- CentOS 7 Update GCC G++
curl https://ftp.gnu.org/gnu/gcc/gcc-5.4.0/gcc-5.4.0.tar.bz2 -O echo "extracting files..." ...
- 搭建Ganglia乱码及其他问题总汇
搭建Ganglia乱码及其他问题 搭建完Ganglia监控后图像显示正常,但是文字却显示都是小方框,最后确定是由于系统缺少字体导致的, /usr/share/fonts/ Centos默认存放字体的 ...
- 1147 Heaps
1147 Heaps(30 分) In computer science, a heap is a specialized tree-based data structure that satisfi ...
- 转载:细说oracle 11g rac 的ip地址
本文转载自:细说oracle 11g rac 的ip地址 http://blog.sina.com.cn/s/blog_4fe6d4250102v5fa.html 以前搭建oracle rac的时候( ...