博客
关于我
leetcode 440第k个字典序的数字【1】
阅读量:198 次
发布时间:2019-02-28

本文共 931 字,大约阅读时间需要 3 分钟。

???1?n???k??????????????????????????????????????????????????

  • ????????cur=1???k?1?????????1??
  • ???????k??0?
  • ?????????????cur??????????????steps?
  • ??k????
    • ??steps<=k???????????????????????
    • ?????????????k-steps?
  • ??????k??0?????????
  • ??????????????????????????????????????????

    ?????

    public int findKthNumber(int n, int k) {    int cur = 1;    k--; // ????????1    while (k > 0) {        long long step = 0, first = cur, last = cur + 1;        while (first <= n) {            step += (last <= n) ? (last - first) : (n - first + 1);            first *= 10;            last *= 10;        }        if (step <= k) {            cur++;            k -= step;        } else {            cur *= 10;            k--;        }    }    return cur;}

    ???

    • ???????1???k??0?????????1??
    • ?????k>0????
    • ??????????????????????????steps?
    • ?????????????k???????????????????????
    • ?????????????????k????????????????
    • ????k??0?????????

    ???????????????????????????n??????

    转载地址:http://giki.baihongyu.com/

    你可能感兴趣的文章
    Python中的文本和字节序列
    查看>>
    python中的方法_Python中看起来高大上的技术
    查看>>
    PYTHON中的测地距离变换
    查看>>
    Python中的私有方法
    查看>>
    Python中的空元组是“常量“吗?
    查看>>
    Python中的类-ChatGPT4o作答
    查看>>
    Python中的类中的池
    查看>>
    python中的装饰器基础
    查看>>
    python中的负零
    查看>>
    Python中的进程通信
    查看>>
    Python中的递归有多安全?
    查看>>
    python中程序如何获取实现多行输入
    查看>>
    python中算法与数学_中国古代数学算法的Python实现
    查看>>
    python中类的实例化_python类的实例化
    查看>>
    Python中类的约束
    查看>>
    python中自定义sort 规则
    查看>>
    python中自定义错误_在现代Python中声明自定义异常的正确方法?
    查看>>
    python中获取上一个月一号的方法
    查看>>
    python中蜂窝网格边缘的坐标
    查看>>
    Python中表示偶数_分享一组 Python 高效编程的实用技巧
    查看>>