【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;

posted on 2019-07-18 09:56  鹅要长大  阅读(155)  评论(0编辑  收藏  举报

导航