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. ACM学习历程——UVA 127 "Accordian" Patience(栈;模拟)

    Description  ``Accordian'' Patience  You are to simulate the playing of games of ``Accordian'' patie ...

  2. Android的各国语言的缩写

    语言包在android工程中的对应关系: 中文(中国):values-zh-rCN 中文(台湾):values-zh-rTW 中文(香港):values-zh-rHK 英语(美国):values-en ...

  3. C#如何对DataTable中的数据进行条件搜索

    经常遇到将数据库中的数据读取到DataTable中的时候再次对DataTable进行条件筛选,下面的筛选的一个例子: DataRow[] dr = dt.Select("token = '& ...

  4. SQL中top使用方法

    转自:https://www.cnblogs.com/wang7/archive/2012/07/09/2582891.html 1. 在编写程序中,我们可能遇到诸如查询最热门的5篇文章或返回满足条件 ...

  5. [matlab]一道笔试题

    x=[1 1; 1 -1; -1 -1; -1 1]'; X=-2:0.01:2; Y=X; N=length(X); [X,Y]=meshgrid(X,Y); Z1=0;Z2=0;Z3=0;Z4=0 ...

  6. 在64位ubuntu上安装alienbrain客户端

    一.首先从Alienbrain_EN_10.5.zip安装包(网上可搜索下载)里提取出linux版安装文件:Installations/Clients/Linux/NoVM/install.bin并c ...

  7. 10、Perl5中19个最重要的文件系统工具

    转载:http://www.cnblogs.com/nkwy2012/p/6027157.html 在写脚本处理文件系统时,经常需要加载很多模块.其中好多有用函数分散在各种不同的模块中.它们有些是Pe ...

  8. Windows 7,无法访问internet,DNS无响应

    我电脑网络连接显示有internet访问,但是网页打不开,QQ上不了,但可以PING通谷歌DNS 8.8.8.8,一PING域名就无法解析. 解决方法:开始-运行-输入"netsh wins ...

  9. 结合jenkins以及PTP平台的性能回归测试

    此文已由作者余笑天授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 1背景简介 1.1 jenkins Jenkins是一个用Java编写的开源的持续集成工具.在与Oracle ...

  10. 【leetcode 105. 从前序与中序遍历序列构造二叉树】解题报告

    前往 中序,后序遍历构造二叉树, 中序,前序遍历构造二叉树 TreeNode* build(vector<int>& preorder, int l1, int r1, vecto ...