Skip to content

Commit

Permalink
Create Sequential Digits.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayu-99 authored Jan 23, 2022
1 parent c347886 commit 9fffdbb
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Leetcode Challenge/January/Java/Sequential Digits.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
public List<Integer> sequentialDigits(int low, int high) {
List<Integer> res = new ArrayList();
for (int i = 1; i <= 9; i++) {
helper(0, i, low, high, res);
}
Collections.sort(res);
return res;
}

void helper(int cur, int digit, int low, int high, List<Integer> res) {
cur = cur * 10 + digit;
if (cur > high)
return;

if (cur >= low) {
res.add(cur);
}

if (digit + 1 <= 9)
helper(cur, digit + 1, low, high, res);
}

0 comments on commit 9fffdbb

Please sign in to comment.