Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public List<Integer> lexicalOrder(int n) {
- ArrayList<Integer> res = new ArrayList<Integer>();
- int curr = 1;
- while(res.size() < n){
- res.add(curr);
- if(curr * 10 <= n){
- curr = curr * 10;
- }else{
- if(curr + 1 > n){
- curr/=10;
- }
- while(curr%10 == 9){
- curr/=10;
- }
- curr++;
- }
- }
- return res;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement