(int n)
| 1 | //DFS |
| 2 | class Solution { |
| 3 | public List<Integer> lexicalOrder(int n) { |
| 4 | List<Integer> res = new ArrayList<>(); |
| 5 | for(int i=1;i<10;i++){ |
| 6 | if(i>n) break; |
| 7 | dfs(i,n,res); |
| 8 | } |
| 9 | return res; |
| 10 | } |
| 11 | public void dfs(int curNum, int target, List<Integer>res){ |
| 12 | if(curNum>target){ |
| 13 | return; |