当前位置:网站首页>44. a digit in a sequence of digits
44. a digit in a sequence of digits
2022-06-12 05:20:00 【Be your goat】
The finger of the sword Offer 44. A number in a sequence of numbers
Ideas : iteration + Integer / Seeking remainder
- determine n Number of digits
- determine n The number in which
- determine n yes num Which digit of
1. determine n Number of digits
Loop execution n Subtract one digit , Double digits ,… The number of count, until n<=count Jump out of .
2. Determine the number where the desired digit is located
n u m = s t a r t + ( n − 1 ) / / d i g i t num=start+(n-1)//digit num=start+(n−1)//digit
3. Determine what is required num Which digit of
s=str(num)
res=s[(n-1)%digit]-'0';
class Solution {
public:
int findNthDigit(int n) {
int digit=1;
long start=1;
long count=9*digit*start;
while(n>count){
n-=count;
digit++;
start*=10;
count=long(9)*digit*start;
}
int num=start+(n-1)/digit;
int res=to_string(num)[(n-1)%digit]-'0';
return res;
}
};
Time complexity O(logn)
Spatial complexity O(logn) Convert numbers to strings , Occupy O(logn) Extra space
边栏推荐
- 62. the last number left in the circle
- Day18 creation and restoration of sparse array
- JS set the position of the current scroll bar
- Qs100 at command mqtt access thingsboard
- Ubunt 20.04 uses CDROM or ISO as the installation source
- 20. string representing numeric value
- Introduction to audio alsa architecture
- Multi thread learning 4. Sleep, wait, yield, join (), ThreadGroup control the running of threads
- [backtracking] backtracking method to solve combinatorial problems
- Rv1109 lvgl UI development
猜你喜欢

MySQL Linux Installation mysql-5.7.24

When the build When gradle does not load the dependencies, and you need to add a download path in libraries, the path in gradle is not a direct downloadable path

Acquisition of Lai data, NPP data, GPP data and vegetation coverage data

Detailed explanation of data envelopment analysis (DEA) (taking the 8th Ningxia provincial competition as an example)

Can‘t find a suitable configuration file in this directory or any parent. Error reporting and resolution

cellular automaton

Normalized vegetation index (NDVI) data, NPP data, GPP data, evapotranspiration data, vegetation type data, ecosystem type distribution data

Accumulated temperature spatial distribution data, temperature distribution data, sunshine data, rainfall distribution, solar radiation data, surface runoff data, land use data, NPP data, NDVI data
![[GIS tutorial] ArcGIS for sunshine analysis (with exercise data download)](/img/60/baebffb2024ddf5f2cb070f222b257.jpg)
[GIS tutorial] ArcGIS for sunshine analysis (with exercise data download)

Quickly get PCA (principal component analysis) (principle code case)
随机推荐
Difference between thread and task
New knowledge today
Spatial distribution data of China's tertiary watershed / national new area distribution data /npp net primary productivity data / spatial distribution data of vegetation cover / land use data /ndvi d
Platform of ASoC framework driven by alsa
Pupanvr- establishment of development environment and diary, addition of some basic tool functions (3)
Microsoft announces that it will discontinue support for older versions of visual studio
Object class not ended
Some problems of Qinglong panel
asp. Net core theme Middleware
JS to determine whether the tags of multiple classes are empty
[cjson] precautions for root node
Please remove any half-completed changes then run repair to fix the schema history
Variables and data types
When the build When gradle does not load the dependencies, and you need to add a download path in libraries, the path in gradle is not a direct downloadable path
JS to determine whether it is the first time to browse the web page
MySQL5.7.21 Build For ARM
Yolov5 realizes road crack detection
Ray. Tune visual adjustment super parameter tensorflow 2.0
Applet pull-down load refresh onreachbottom
Servlet core technology