Pre order C++


  • 0
    B

    class Solution {
    public:

    vector<int> lexicalOrder(int n) {
        for(int i=1;i<10;i++)
        find_next(i,n);
        return result;
    }
    void find_next(int i,int n)
    {
        if(i>n)return;
        result.push_back(i);
        for(int j=0;j<10;j++)
        {
            find_next(i*10+j,n);
        }
        return;
    }
    vector<int> result;
    

    };


Log in to reply
 

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