OK in custom test case, but got "Output Limit Exceeded" if submit?


  • 0
    K
    public:
    vector<string> findStrobogrammatic(int n) 
    {
        static int const NUM = n;
        static string const single[3] = {"0", "1", "8"};
        static string const pair[5] = {"00", "11", "69", "88", "96"}; 
        vector<string> ret;
        if(n == 0)
            return ret;
        if(n == 1)
            ret.assign(single, single+3);
        if(n == 2)
            ret.assign(pair+1, pair+5);
        if(n > 2)
        {
            vector<string> inner = findStrobogrammatic(n-2);
            if(n == 4)
                inner.insert(inner.begin(), "00");
            const int N = inner.size();
            int i = (n == NUM) ? 1 : 0, m = i ? 4 : 5;
            ret.reserve(m*N);
            for(; i<5; ++i)
                for(int j=0; j<N; ++j)
                    ret.push_back(pair[i][0] + inner[j] + pair[i][1]);
        }
        return ret;
    }
    

    I tried n = 13 in custom test case, and the output is correct. However, I got "Output Limit Exceeded" when submit it. What's the issue here?

    Thanks in advance


  • 2
    R

    Try to factor out all numbers start with 0 because numbers cannot start with 0.
    Good luck


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.