Leetcode 400. Nth Digit[easy]
来源:互联网 发布:excel2007编程实例vb 编辑:程序博客网 时间:2024/06/03 09:36
题目:
Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, …
Note:
n is positive and will fit within the range of a 32-bit signed integer (n < 231).
Example 1:
Input:
3
Output:
3
Example 2:
Input:
11
Output:
0
Explanation:
The 11th digit of the sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, … is a 0, which is part of the number 10.
继续混题数。
wa了一次,没注意到位数*此位数数字的个数有可能爆int。
class Solution {public: int findNthDigit(int n) { return find(1, n); } int find(int w, int n) { int num = max(w) - min(w) + 1; if ((long long)n > (long long)w * num) return find(w + 1, n - w * num); else { int q = (n - 1) / w; int r = (n - 1) % w; r++; n = min(w) + q; r = w - r; while (r--) n /= 10; return n % 10; } } int max(int w) { int rt = 0; while (w--) rt = rt * 10 + 9; return rt; } int min(int w) { int rt = 1; w--; while (w--) rt *= 10; return rt; }};
0 0
- Leetcode 400. Nth Digit[easy]
- Leetcode 400. Nth Digit (Easy) (cpp)
- 【Leetcode】400. Nth Digit
- leetcode 400. Nth Digit
- 400. Nth Digit (leetcode) 。。。
- [LeetCode]400. Nth Digit
- [leetcode] 400. Nth Digit
- [LeetCode]--400. Nth Digit
- leetcode 400. Nth Digit
- LeetCode 400. Nth Digit
- [leetcode]400. Nth Digit
- Leetcode 400. Nth Digit
- LeetCode 400. Nth Digit
- 【LeetCode】 400. Nth Digit
- LeetCode 400. Nth Digit
- LeetCode 400. Nth Digit
- LeetCode 400. Nth Digit
- LeetCode-400. Nth Digit
- 在Spring框架中进行面向切向的程序设计(AOP:Aspect Oriented Programming)
- httpClient使用方法
- 数据库学习
- hadoop 2.7.1 高可用安装部署
- float x 与“零值”比较
- Leetcode 400. Nth Digit[easy]
- 深入理解Java:注解(Annotation)自定义注解入门
- Robot Motion(模拟法)
- ios 开发 NSString 正确遍历字符个数方式 (surrogate pairs)
- webuploader解决不能重复上传问题
- 若有x = 1,y = 2, z = 3,则表达式(x<y?x:y)==z++的值?
- FreeRTOS代码剖析之5:链表管理list.c
- centos下安装jdk后,出现该错误cannot execute binary file
- 原迹手写之贝赛尔曲线(穿过已知点画平滑曲线(3次贝塞尔曲线)