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. 启用Linux云平台oracle数据库实口令复杂性函数:PASSWORD_VERIFY_FUNCTION=NULL

    第一步:采用putty.exe登录数据库服务器. 输入IP后点击“Open”按钮: 第二步:登录对应的数据库实例. 执行:# su – oracle 查找:$ps -ef | grep pmon 找到 ...

  2. pytorch 调用forward 的具体流程

    forward方法的具体流程: 以一个Module为例:1. 调用module的call方法2. module的call里面调用module的forward方法3. forward里面如果碰到Modu ...

  3. Oracle 12C 新特性之扩展数据类型(extended data type)

    Oracle 12C 新特性-扩展数据类型,在12c中,与早期版本相比,诸如VARCHAR2, NAVARCHAR2以及 RAW这些数据类型的大小会从4K以及2K字节扩展至32K字节.只要可能,扩展字 ...

  4. bzoj 3157 & bzoj 3516 国王奇遇记 —— 推式子

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3157 https://www.lydsy.com/JudgeOnline/problem.p ...

  5. Qt安装与配置

    安装Qt 安装Qt Creator,打开终端执行如下命令: sudo apt-get install qt5-default qtcreator -y 安装Qt示例和文档: sudo apt-get ...

  6. 使用变参函数实现pwd命令

    #include "stdafx.h"#include <Windows.h> #define DIRNAME_LEN (MAX_PATH+2) BOOL PrintS ...

  7. Web Form要“jquery”ScriptResourceMapping。请添加一个名为 jquery (区分大小写)的 ScriptResourceMapping。”的解决办法。

    1.先将aspnet.scriptmanager.jquery.dl 复制到bin  (网站根目录下的bin文件夹找不到,看看下面的图片中点击[显示所有文档])  文件夹下.   2.在网站根目录下s ...

  8. AngularJS(Part 10)--页面导航

    页面导航     过去,一个URL代表一个页面.但是随着Ajax的兴起,情况发生的很大的变化.不同的内容可以使用同一个URL.这让浏览器中的回退.前进甚至收藏按钮都失去了作用.而AngularJS提供 ...

  9. 1、perl学习

    1.字符串函数 print chomp chop length uc lc index ord #转符号为ASCII的数字 chr #转数字为ASCII的字母 substr($string,offse ...

  10. C#z中的虚方法,抽象类

    1.虚方法 我在这动物类中定义了一个虚方法 Dosth class Animal { public int Aid; public string Name; public void SetAid(in ...