Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public List<Integer> lexicalOrder(int n) {
- List<Integer> result = new ArrayList<>();
- if (n <= 0) {
- return result;
- }
- for (int i=1; i<10; i++) {
- dfs(i, n, result);
- }
- return result;
- }
- public void dfs(int cur, int n, List<Integer> res) {
- if (cur > n) {
- return;
- }
- res.add(cur);
- for (int i=0; i<10; i++) {
- int newCur = cur*10 + i;
- if (newCur > n) {
- return;
- }
- dfs(newCur, n, res);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement