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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. LeetCode Weekly Contest 8

    LeetCode Weekly Contest 8 415. Add Strings User Accepted: 765 User Tried: 822 Total Accepted: 789 To ...

  5. leetcode weekly contest 43

    leetcode weekly contest 43 leetcode649. Dota2 Senate leetcode649.Dota2 Senate 思路: 模拟规则round by round ...

  6. LeetCode Weekly Contest 23

    LeetCode Weekly Contest 23 1. Reverse String II Given a string and an integer k, you need to reverse ...

  7. Leetcode Weekly Contest 86

    Weekly Contest 86 A:840. 矩阵中的幻方 3 x 3 的幻方是一个填充有从 1 到 9 的不同数字的 3 x 3 矩阵,其中每行,每列以及两条对角线上的各数之和都相等. 给定一个 ...

  8. LeetCode Weekly Contest

    链接:https://leetcode.com/contest/leetcode-weekly-contest-33/ A.Longest Harmonious Subsequence 思路:hash ...

  9. 【LeetCode Weekly Contest 26 Q4】Split Array with Equal Sum

    [题目链接]:https://leetcode.com/contest/leetcode-weekly-contest-26/problems/split-array-with-equal-sum/ ...

随机推荐

  1. 【LeetCode】137. Single Number II

    题目: Given an array of integers, every element appears three times except for one. Find that single o ...

  2. iPhone X机型适配

    1.启动页 启动App,发现App只能居中显示,不能上下充满. 问题产生的原因是:iPhone X是5.8英寸,比5.5英寸的屏幕还要大,没有合适的启动页可以加载,所以只能使用以前5.5英寸的启动页, ...

  3. 代码实现跟控制器跳转到storyBoard

  4. tomcat如何修改发布目录

    tomcat免重启 tomcat访问的时候如何去掉项目名访问: 其中fts是您的项目名. 1.tomcat6.0:<Host></Host>间加了一句<Context p ...

  5. Zeppelin的入门使用系列之创建新的Notebook(一)

    不多说,直接上干货! 前期博客 hadoop-2.6.0.tar.gz + spark-1.6.1-bin-hadoop2.6.tgz + zeppelin-0.5.6-incubating-bin- ...

  6. 在Action获取Scope对象

    引言:在前面的Action操作中,关键就是Action中的exectue方法,但是此方法并没有request.session.application等对象作为参数,自然就不能利用这些对象来操作.下面我 ...

  7. unreal3窗口锁定鼠标开关

    GameViewportClient中有个变量控制是否显示硬件鼠标: var transient bool bDisplayHardwareMouseCursor 也就是系统的光标,一般通过该类中的函 ...

  8. 生物数据库介绍——NCBI

    NCBI(National Center for Biotechnology Information,美国国家生物技术信息中心)除了维护GenBank核酸序列数据库外,还提供数据分析和检索资源.NCB ...

  9. JavaScript: 高级技巧: window 对象也可以添加自定义属性

    JavaScript: 高级技巧: window 对象也可以添加自定义属性 例如 window.ntName = 'a';例如 window.ntXw = top; 优点是, window 无须等加载 ...

  10. IPv4 和 IPv6地址

    目前Internet上使用的基本都是IPv4地址,也就是说地址总共是32个比特位,也就是32位二进制数.  所以IPv4地址总的容量是 2的32次方 = 4294967296 比如 11010010 ...