649ms c++


  • 0
    B
    class Solution {
    public:
        vector<int> ans;
        vector<int> lexicalOrder(int n)
        {
            for(int i=1;i<=9;i++)
                depthSearch(i,n);
            return ans;
        }
        void depthSearch(int p,int n)
        {
            if (p<=n) ans.push_back(p);
            for(int i=0;i<=9;i++)
            {
                int tmpp=p*10+i;
                if (tmpp<=n)
                {
                    depthSearch(tmpp,n);
                }
                else continue;
            }
            return ;
        }
    };
    

Log in to reply
 

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