lexicographical-numbers
Posted 笨鸟居士的博客
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了lexicographical-numbers相关的知识,希望对你有一定的参考价值。
https://leetcode.com/problems/lexicographical-numbers/ public class Solution { public List<Integer> lexicalOrder(int n) { List<Integer> ret = new ArrayList<Integer>(); int cur = 1; ret.add(cur); while (cur > 0) { if (cur * 10 <= n) { cur *= 10; ret.add(cur); continue; } while (cur % 10 == 9) { cur /= 10; } if (cur == 0) { break; } if (cur + 1 <= n) { cur++; ret.add(cur); } else { cur /= 10; while (cur % 10 == 9) { cur /= 10; } if (cur == 0) { break; } cur++; ret.add(cur); } } return ret; } }
以上是关于lexicographical-numbers的主要内容,如果未能解决你的问题,请参考以下文章
386. Lexicographical Numbers 把1--n按字典序排序