400. Nth Digit
2017-01-15 10:53
337 查看
class Solution { public: int findNthDigit(int n) { /* * 首先定位到包含n的这个数字有几位 * 然后定位到包含n的这个数字是什么 * 最后定位到n是这个数字的第几位 */ long digit=1,base=9,ith=1;//digit表示位数 base 表示digit位数的数字有多少个 while(n>digit*base) { n-=(digit*base); ith+=base; digit++; base*=10; } return to_string(ith+(n-1)/digit)[(n-1)%digit]-'0'; } };
相关文章推荐
- 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
- 400. Nth Digit
- leetcode 400. Nth Digit解题报告
- 400. Nth Digit
- Leetcode 400. Nth Digit[easy]
- LeetCode 400. Nth Digit
- 400. Nth Digit
- 400. Nth Digit
- 400. Nth Digit
- 400. Nth Digit
- LeetCode 400. Nth Digit
- 400. Nth Digit