Skip to content

Commit 779349c

Browse files
Create 1291-sequential-digits.java
1 parent d2af5f9 commit 779349c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

java/1291-sequential-digits.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public List<Integer> sequentialDigits(int low, int high) {
3+
List<Integer> res = new ArrayList<>();
4+
Queue<Integer> q = new LinkedList<>();
5+
for(int i = 1; i < 10; i++)
6+
q.add(i);
7+
8+
while(!q.isEmpty()){
9+
int n = q.poll();
10+
if(n > high)
11+
continue;
12+
if(n >= low && n <= high)
13+
res.add(n);
14+
int ones = n % 10;
15+
if(ones < 9)
16+
q.add(n * 10 + (ones + 1));
17+
}
18+
return res;
19+
}
20+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy