LeetCode 386. Lexicographical Numbers

来源:互联网 发布:php 截取字符串 编辑:程序博客网 时间:2024/05/16 17:53
public class Solution {    public List<Integer> lexicalOrder(int n) {        List<Integer> list = new ArrayList<Integer>();        int num = 1;        for (int i = 1; i <= n; i++) {        list.add(num);        if (num * 10 <= n) num *= 10;        else if (num % 10 < 9 && num + 1 <= n) num++;        else {        while ((num / 10 % 10) == 9) num /= 10;        num = num / 10 + 1;        }        }        return list;    }}

0 0
原创粉丝点击