https://leetcode.com/problems/nth-digit/

public class Solution {
public int findNthDigit(int n) {
int k = 9;
int b = 1;
// 需要加上对b的限制
while (b < 9 && n > k*b) {
n -= k * b;
k *= 10;
b ++;
}
int rank = (n - 1) / b;
int app = (n - 1) % b;
int num = (int)Math.pow(10, b-1) + rank;
for (int i=b-1; i>app; i--) {
num /= 10;
}
return num % 10;
}
}

nth-digit的更多相关文章

  1. [LeetCode] Nth Digit 第N位

    Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... Note: n i ...

  2. Leetcode: Nth Digit

    Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... Note: n i ...

  3. hdu 1597 find the nth digit

    find the nth digit Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  4. Nth Digit | leetcode

    Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... Note: n i ...

  5. find the nth digit(二分查找)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1597 find the nth digit Time Limit: 1000/1000 MS (Jav ...

  6. [Swift]LeetCode400. 第N个数字 | Nth Digit

    Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... Note:n is ...

  7. C++版 - Leetcode 400. Nth Digit解题报告

    leetcode 400. Nth Digit 在线提交网址: https://leetcode.com/problems/nth-digit/ Total Accepted: 4356 Total ...

  8. (lower_bound)find the nth digit hdu1597

    find the nth digit Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  9. LeetCode——Nth Digit

    Question Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... ...

  10. hdu 1597 find the nth digit (数学)

    find the nth digit Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

随机推荐

  1. Mac下思维导图Xmind使用入门

    1.软件下载 中文官网地址: http://www.xmindchina.net   安装过程比较傻瓜化,这里就不截图了. 2.用Xmind设计软件模块: 1>.新建一个思维导图,如下图,选 ...

  2. thinkphp每次跳转时都会显示笑脸的修改

    Success和error方法都有对应的模板,并且是可以设置的,默认的设置是两个方法对应的模板都是://默认错误跳转对应的模板文件'TMPL_ACTION_ERROR' => THINK_PAT ...

  3. iOS 11开发教程(七)编写第一个iOS11代码Hello,World

    iOS 11开发教程(七)编写第一个iOS11代码Hello,World 代码就是用来实现某一特定的功能,而用计算机语言编写的命令序列的集合.现在就来通过代码在文本框中实现显示“Hello,World ...

  4. 机器学习之路:python 集成分类器 随机森林分类RandomForestClassifier 梯度提升决策树分类GradientBoostingClassifier 预测泰坦尼克号幸存者

    python3 学习使用随机森林分类器 梯度提升决策树分类 的api,并将他们和单一决策树预测结果做出对比 附上我的git,欢迎大家来参考我其他分类器的代码: https://github.com/l ...

  5. BZOJ 1061: [Noi2008]志愿者招募 [单纯形法]【学习笔记看另一篇吧】

    1061: [Noi2008]志愿者招募 Time Limit: 20 Sec  Memory Limit: 162 MBSubmit: 3975  Solved: 2421[Submit][Stat ...

  6. GITC简单感触

    GITC短暂的2天,去参加主要是想参与其中,了解其他家的技术,技术使用, 那些大牛,及大牛公司,大牛团队的一些事. 早上的主会场主要是介绍和宣传.半小时后就出去逛逛外面的分会场: 参与听了下 智能硬件 ...

  7. BZOJ 4380 Myjnie 区间DP

    4380: [POI2015]Myjnie Time Limit: 40 Sec  Memory Limit: 256 MBSec  Special JudgeSubmit: 162  Solved: ...

  8. spring---aop(10)---Spring AOP中AspectJ

    写在前面 在之前的文章中有写到,Spring在配置中,会存在大量的切面配置.然而在很多情况下,SpringAOP 所提供的切面类真的不是很够用,比如想拦截制定的注解方法,我们就必须扩展DefalutP ...

  9. 使用Device IO Control 讀寫 USB Mass Storage

    http://www.ezblog.idv.tw/Download/USBStorage.rar 這是一個不透過檔案系統,去讀寫USB Mass Storage 任何位置(包含FAT)的方式 首先需安 ...

  10. debuginfo-install glibc-2.17-157.el7.x86_64

    Running transaction Installing : glibc-debuginfo-common-.el7.x86_64 / Installing : glibc-debuginfo-. ...