【Leetcode_easy】788. Rotated Digits

problem

788. Rotated Digits

solution1:

class Solution {
public:
    int rotatedDigits(int N) {
        int res = 0;
        for(int i=1; i<=N; ++i)
        {
            if(check(i)) res++;
        }
        return res;
    }
    bool check(int num)
    {
        string str = to_string(num);
        bool flag = false;
        for(auto ch:str)
        {
            if(ch=='3'||ch=='4'||ch=='7') return false;
            if(ch=='2'||ch=='5'||ch=='6'||ch=='9') flag = true;
        }
        return flag;
    }
};

参考

1. Leetcode_easy_788. Rotated Digits;

2. Grandyang;

原文地址:https://www.cnblogs.com/happyamyhope/p/11205274.html