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 ...
随机推荐
- PS抠图之单色背景图片
PS一直大家比较喜欢的一款图像处理软件,很多朋友对使用基本的功能.最近很多的朋友都在问我关于PS抠图的方法,这些方法也不是一句两句就能说清楚,并且每天都重复的叫他们,不如直接写出来刚刚接触到的朋友一起 ...
- initWithImage和imageWithContentsOfFile的区别
UIImageView *imageView = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@"icon ...
- vc++ windows 快速启动栏创建快捷方式
创建快速启动栏 在windows软件开发中,软件安装过程中总是需要在快速启动栏创建快捷方式,下面介绍一种快速启动栏创建快捷方式的方法,具体代码如下:(该方法不支持win10,目前还没有找到win10的 ...
- vue指令总结
new Vue({ el: "#box", // element(元素) 当前作用域 data:{ msg:" ...
- Maven依赖调解
引用来自maven实战中的一段话.
- Ubantu中sublime汉化
1 启动并进入sublime主界面: 2 如图所示,点击菜单栏中“preferences”,弹出选项中找到“package control”: 3 进入下一步,选择“install package”: ...
- 省略名词: 从 Please find the attached 说起
为什么是attached 首先需要解释的,为什么是叫attached: When you would like a person to reference a document attached to ...
- bzoj 4881 [Lydsy1705月赛]线段游戏
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4881 1.当一块相互交织的线段中有3个或以上两两相交的那种线段时,无解. 这就是最长下降子序 ...
- LaunchImage添加以及设置无效处理
1.添加LaunchImage 2.添加所需要图片即可,出现un..可以删除,警告也随之而去,并删除LauchImage Assets之后重新添加 3.确定设置是否一样 4.发现启动后加载不了启动图, ...
- spring mvc 返回字符串带双引号及StringHttpMessageConverter乱码处理
本文转载自:http://blog.csdn.net/wangyangbto/article/details/48804155 很多人都碰到过,SpringMVC使用 @ResponseBody 注解 ...