classSolution{ public List<Integer> lexicalOrder(int n){ List<Integer> res = new ArrayList<>(); for (int i = 1; i <= 9; i++){ helper(i, n, res); } return res; } privatevoidhelper(int cur, int n, List<Integer> res){ if (cur > n){ return; } res.add(cur); for (int i = 0; i <= 9; i++){ int newInt = cur * 10 + i; if (newInt > n) return; helper(newInt, n, res); } } }