73th LeetCode Weekly Contest 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. 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.
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]
.
讲的是数字倒过来能不能变成其他数字啦,不是那种翻转哦。
那么1,8,0是不会变的,2,5,6,9会变,其他变不了,那么我们只需要判断存在2,5,6,9这些就好了
class Solution {
public:
int flag(string str){
int len=str.length();
if(len==){
for(int i=;i<len;i++){
if(str[i]==''||str[i]==''||str[i]==''||str[i]==''){
return ;
}else{
return ;
}
}
}
int fit=,fis=;
for(int i=;i<len;i++){
if(str[i]==''||str[i]==''||str[i]==''||str[i]==''){
fit=;
}else if(str[i]==''||str[i]==''||str[i]==''){
fis=;
}else{
return ;
}
}
if(fit==){
return ;
}else{
return ;
}
}
int rotatedDigits(int N) {
int dis=;
for(int i=;i<=N;i++){
string Str="";
int num=i;
while(num){
Str+=((num%)+'');
num/=;
}
if(flag(Str)){
// cout<<Str<<endl;
dis++;
}
//cout<<Str<<" "<<i<<endl;
}
return dis;
}
};
73th LeetCode Weekly Contest Rotated Digits的更多相关文章
- 73th LeetCode Weekly Contest Domino and Tromino Tiling
We have two types of tiles: a 2x1 domino shape, and an "L" tromino shape. These shapes may ...
- 73th LeetCode Weekly Contest Custom Sort String
S and T are strings composed of lowercase letters. In S, no letter occurs more than once. S was sort ...
- 73th LeetCode Weekly Contest Escape The Ghosts
You are playing a simplified Pacman game. You start at the point (0, 0), and your destination is(tar ...
- LeetCode Weekly Contest 8
LeetCode Weekly Contest 8 415. Add Strings User Accepted: 765 User Tried: 822 Total Accepted: 789 To ...
- leetcode weekly contest 43
leetcode weekly contest 43 leetcode649. Dota2 Senate leetcode649.Dota2 Senate 思路: 模拟规则round by round ...
- LeetCode Weekly Contest 23
LeetCode Weekly Contest 23 1. Reverse String II Given a string and an integer k, you need to reverse ...
- Leetcode Weekly Contest 86
Weekly Contest 86 A:840. 矩阵中的幻方 3 x 3 的幻方是一个填充有从 1 到 9 的不同数字的 3 x 3 矩阵,其中每行,每列以及两条对角线上的各数之和都相等. 给定一个 ...
- LeetCode Weekly Contest
链接:https://leetcode.com/contest/leetcode-weekly-contest-33/ A.Longest Harmonious Subsequence 思路:hash ...
- 【LeetCode Weekly Contest 26 Q4】Split Array with Equal Sum
[题目链接]:https://leetcode.com/contest/leetcode-weekly-contest-26/problems/split-array-with-equal-sum/ ...
随机推荐
- 批量清除过期的binlog释放磁盘空间
方案,总共24台db,一台台进去清理肯定不行,得需要写一个脚本,进行批量操作,方案思路大概如下 1, 建立双master列表masterlist; 一个master一行. 2,远程获取master ...
- poj 1208 Web Navigation(堆栈操作)
一.Description Standard web browsers contain features to move backward and forward among the pages re ...
- 【转】 Pro Android学习笔记(七九):服务(4):远程服务的实现
目录(?)[-] 远程服务的实现小例子 对外开放远程服务的接口 文章转载只能用于非商业性质,且不能带有虚拟货币.积分.注册等附加条件.转载须注明出处:http://blog.csdn.net/flow ...
- 【转】 Pro Android学习笔记(七七):服务(2):Local Service
目录(?)[-] Local service代码 调用Local ServiceLocal Service client代码 AndroidManifestxml定义Serviceacitivty的l ...
- mac tree 命令
mac下默认是没有 tree命令的,不过我们可以使用find命令模拟出tree命令的效果,如显示当前目录的 tree 的命令: find . -print | sed -e 's;[^/]*/;|__ ...
- 问题:Oracle long 类型l;结果:oracle里long类型的总结
oracle里long类型的总结 1.LONG 数据类型中存储的是可变长字符串,最大长度限制是2GB. 2.对于超出一定长度的文本,基本只能用LONG类型来存储,数据字典中很多对象的定义就是用LONG ...
- Ubuntu 切换root用户是时出现su Authentication failure
su root 时出现错误su Authentication failure 原因是没有给root用户设置密码 sudo passwd root
- Linux查看并修改mysql的编码
系统:阿里云 一.查看mysql字符集 输入:show variables like 'character_set_%'; 二.修改某一个数据库的编码 输入:alter database dbname ...
- 14、/proc/cpuinfo 文件(查看CPU信息)
转载http://www.cnblogs.com/itcomputer/p/4888438.html /proc/cpuinfo文件分析 根据以下内容,我们则可以很方便的知道当前系统关于CPU.CPU ...
- 第 2 章 Python 语言入⻔
目录 2.1低而长的学习曲线 2.2Python的优势 2.3在你的计算机中安装Python 2.4如何运行Python程序 2.5文本编辑器 2.6寻求帮助 Python语言是一种流行的编程语言,在 ...