<p>Given an integer <code>n</code>, return all the numbers in the range <code>[1, n]</code> sorted in lexicographical order.</p>

<p>You must write an algorithm that runs in&nbsp;<code>O(n)</code>&nbsp;time and uses <code>O(1)</code> extra space.&nbsp;</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> n = 13
<strong>Output:</strong> [1,10,11,12,13,2,3,4,5,6,7,8,9]
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> n = 2
<strong>Output:</strong> [1,2]
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= n &lt;= 5 * 10<sup>4</sup></code></li>
</ul>

struct Trie{
    struct Node {
        Node * child[10];
        int data;
        bool isEnd;
        Node(){
            for (int i =0 ;i<10;i++)
                child[i] = NULL;
            data =-1;
            isEnd= false;
        }
    };
    Node* root;
    int numberNode=0;
    Trie(){
        root = new Node();
    }
    void insert(int a){
        Node *cur =root;
        string s= to_string(a);
        for (int i=0 ;i<s.length();i++){
            int num = s[i]-'0';
            if (cur->child[num]== NULL) {
                cur->child[num] = new Node();
                numberNode++;
            }
                cur= cur->child[num];
        }
        cur->isEnd= true;
        cur->data = a;
    }
};
class Solution{
    void  DFS(Trie::Node* root){
        if (root->isEnd)
            ans.push_back(root->data);
        for (int i =0 ;i<10;i++)
            if(root->child[i]) DFS(root->child[i]);
    }
    vector<int>ans;
    public:
    vector<int> lexicalOrder(int t) {
        Trie *root = new Trie();
        for (int i=1 ;i<=t;i++){
            root->insert(i);
        }
        DFS(root->root);
        return ans;
    }
};
27720