执行用时 : 0 ms, 在Rotated Digits的C++提交中击败了100.00% 的用户
内存消耗 : 8.4 MB, 在Rotated Digits的C++提交中击败了53.91% 的用户
第一次靠自己在一道题上刷到100%,在此记录一下,以此勉励自己。
class Solution {
public:
int res = 0;
int rotatedDigits(int N) {
for(int i=2;i<=N;i++)
{
int bi = 0;
int tm = i;
bool tt = false;
while(tm)
{
int t = tm%10;
bi++;//用来记录一个数字遍历到了哪一位
if(t==3 || t==4 || t==7)
{
//如果这一位等于3,4,7就应该直接跨越整倍数,比如271,就直接break,从280开始接着查
if(bi>=2)
{
i = (i/(pow(10,bi-1)))+1;
i = i*pow(10,bi-1);
i--;
}
break;
}//当除去数字中有3,4,7的数字后,剩下的数字中只要有一下中的某一位,就算有效
else if((t==2 || t==5 || t==6 || t==9)&&!tt)
{
tt = true;
}
tm/=10;
}
if(tt && !tm)
res++;
}
return res;
}
};
如有更好的办法还请大佬指点。