386. 字典序排数(多叉树遍历)

   分析:十叉树的遍历

class Solution {
    public List<Integer> lexicalOrder(int n) {
        List<Integer> res = new ArrayList<>();
        for(int i = 1; i < 10; i++) {
            dfs(n,res,i);
        }
        return res;
    }
    public void dfs(int n, List<Integer> list, int i) {
        if(i > n) return;
        list.add(i);
        i*=10;
        for(int k = 0; k < 10; k++) {
            dfs(n,list,i+k);
        }
    }
}
原文地址:https://www.cnblogs.com/yonezu/p/13559762.html