---
# System prepended metadata

title: 386. Lexicographical Numbers
tags: [LeetCode]

---

# 386. Lexicographical Numbers
###### tags: `LeetCode`
## **Link**
https://leetcode.com/problems/lexicographical-numbers/
## **Code**
```cpp=
class Solution {
public:
    void dfs(vector<int> &ans, int now, int n)
    {
        ans.push_back(now);
        if(now*10<=n) // 10倍優先
            dfs(ans,now*10,n);
        if(now<n && now%10!=9) // +1第二優先
            dfs(ans,now+1,n);
    }
    
    vector<int> lexicalOrder(int n) {
        vector<int> ans;
        dfs(ans,1,n);
        return ans;
    }
};
```
## date
**2023.01.20**

{%hackmd @nnks8908/background_leetcode %}