这个EASY难度的题怎么感觉比H的还难,昨天没做出来,今天才做出来。。

呃啊。。我生 气 啦。。 直接看的答案,耻辱。

1 digit:

1~9 总共1×9个

2 digits:

10~99 总共2×90个

3 digits:

100~999 总共3×900个

..

.....

所以就是先定位大区间,再从区间开始找确切位置。。

public class Solution
{
public int findNthDigit(int n)
{
int digits = 1;
long count = 9;
int pow = 1; while (n > digits * count)
{
n -= digits * count;
digits++;
count *= 10;
pow *= 10;
} pow += (n - 1) / digits;
String s = Integer.toString(pow);
return s.charAt((n - 1) % digits) - '0';
}
}

EASY的难度用了这么久,我一定是病了。

400. Nth Digit的更多相关文章

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

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

  2. leetcode 400 Add to List 400. 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 ...

  3. 【LeetCode】400. Nth Digit 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

  4. 【leetcode❤python】 400. Nth Digit

    #-*- coding: UTF-8 -*- class Solution(object):    def findNthDigit(self, n):        ""&quo ...

  5. [leetcode] 400. Nth Digit

    https://leetcode.com/contest/5/problems/nth-digit/ 刚开始看不懂题意,后来才理解是这个序列连起来的,看一下第几位是几.然后就是数,1位数几个,2位数几 ...

  6. 400 Nth Digit 第N个数字

    在无限的整数序列 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...中找到第 n 个数字.注意:n 是正数且在32为整形范围内 ( n < 231).示例 1:输入:3 ...

  7. [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 ...

  8. Leetcode 400. Nth digits

    解法一: 一个几乎纯数学的解法 numbers:   1,...,9, 10, ..., 99, 100, ... 999, 1000 ,..., 9999, ... # of digits:   9 ...

  9. 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 ...

随机推荐

  1. [转]setTimeout() 函数未定义错误

    用 setTimeout("showMe()",1000) 时出现 showMe is not defined 错误.这是由于showMe() 函数不在 setTimeout 调用 ...

  2. java_反射_及其简单应用(2016-11-16)

    话不多说直接上代码 接口: package bean; /** * user接口 */ public interface User { public String getName(); public ...

  3. 简单的背包变形HDU1203,HDU2955

    今天一直在写背包,不过中间停了一段时间在写shell. 一直在做01背包.今天做了这两题很相似的背包 首先是HDU1203 Speakless很早就想出国,现在他已经考完了所有需要的考试,准备了所有要 ...

  4. MSSQL Server语句

    随机从数据库中取出20条数据:select top 20 * from 表名 order by newid()

  5. 获取动态SQL查询语句返回值(sp_executesql)

    在写存储过程时经常会遇到需要拼接SQL语句的情况,一般情况下仅仅是为了执行拼接后的语句使用exec(@sql)即可. 而今天的一个存储过程却需要获取动态SQL的查询结果. 需求描述:在某表中根据Id值 ...

  6. 读书笔记之 - javascript 设计模式 - 观察者模式

    在事件驱动的环境中,比如浏览器这种持续寻求用户关注的环境中,观察者模式是一种管理人与其任务(确切的讲,是对象及其行为和状态之间的关系)之间的关系的得力工具.用javascript的话来讲,这种模式的实 ...

  7. 帝国cms7.0设置标题图片(缺失状态下)

    有时候因为我们没有设置标题图片,程序就会是使用自己的标题图片,这就是问题所在,现在有2个办法解决这个问题, [1]直接替换调程序的标签图片,但是这样的方法虽然简单,但是图片大小固定,要是每个模版的图片 ...

  8. iOS:Swift界面实例1, 简单界面

    Apple推出了基于Objective-C的新语言Swift. 通过实例, 我们可以很好的感受这门新语言 注意事项: 在XCode6_Beta中, 如果有中文, IDE的自动补全功能就会失效, 所以开 ...

  9. Xcode7之后常见问题整理-b

    一.Xcode7,iOS9之后传出来的什么Xcode有鬼,被植入代码片段什么的,可以看看,了解一下http://drops.wooyun.org/news/8864 二.bitcode问题--未正确设 ...

  10. 对话机器学习大神Yoshua Bengio(下)

    对话机器学习大神Yoshua Bengio(下) Yoshua Bengio教授(个人主页)是机器学习大神之一,尤其是在深度学习这个领域.他连同Geoff Hinton老先生以及 Yann LeCun ...