400. Nth Digit
来源:互联网 发布:修身夹克 知乎 编辑:程序博客网 时间:2024/06/05 09:20
这就是简单数学题。先确定数字的index对应几位数,再利用推导出来的公式带入计算。
class Solution {public: int findNthDigit(int n) { //get range int numSize=1; int low=1; int high=9*pow(10,numSize-1)*numSize; while(1) { if(n>=low&&n<=high) break; numSize++; low=high+1; if(high>=INT_MAX-9*pow(10,numSize-1)*numSize) { high=INT_MAX; break; } else high=high+9*pow(10,numSize-1)*numSize; } //cout<<numSize<<endl; //cout<<(n-low)%numSize<<endl; if((n-low)%numSize==0) return ((n-low)/(numSize*pow(10,numSize-1)))+1; else return ((int)((n-low)/(numSize*pow(10,numSize-1-((n-low)%numSize))))%10); }};
0 0
- 【Leetcode】400. Nth Digit
- 400. Nth Digit
- leetcode 400. Nth Digit
- 400. Nth Digit
- 400. Nth Digit
- 400. Nth Digit (leetcode) 。。。
- [LeetCode]400. Nth Digit
- [leetcode] 400. Nth Digit
- 400. Nth Digit
- [LeetCode]--400. Nth Digit
- 400. Nth Digit
- leetcode 400. Nth Digit
- LeetCode 400. Nth Digit
- 400. Nth Digit
- 400. Nth Digit
- [leetcode]400. Nth Digit
- Leetcode 400. Nth Digit
- 400. Nth Digit
- Linux进程间通信——使用消息队列
- 《论文排版札记》part 4 论文中插入参考文献
- SQL数据操作语言的使用
- 设置开机启动
- java中的JDBC创建步骤--自我总结,我的首篇勿喷...
- 400. Nth Digit
- 【Python】学习笔记——-19、访问数据库
- SeekBar样式修改
- POJ 1270 Following Orders
- Maven实战(四)——基于Maven的持续集成实践
- 第一篇
- Android勒索病毒分析报告-王者荣耀刷皮肤
- iBatis简介及其不适用场合
- python学习(一)常见的数据结构