当前位置:网站首页>17. print from 1 to the maximum n digits
17. print from 1 to the maximum n digits
2022-06-12 05:20:00 【Be your goat】
The finger of the sword Offer 17. Print from 1 To the biggest n digit
Ideas : Divide and conquer algorithm / Full Permutation
For Large Print , Consider that large numbers are out of bounds . So we need to solve :
- Represents the variable type of a large number :string
- Generate a string set of numbers :int Carry of type cannot be applied to string type , Consider using n Bit 0-9 The whole arrangement , It can avoid carry operation
- Recursively generate a full permutation : Based on the idea of divide and conquer algorithm , Fix the high position first , Recursion to low position , When all bits are fixed , Add string
class Solution {
public:
vector<int> nums;
string s;
vector<int> printNumbers(int n) {
s.resize(n);
dfs(n,0);
return nums;
}
void dfs(int end,int index){
if(end==index){
int i=0;
while(i<s.size()&&s[i]=='0')++i;
if(i!=s.size())
nums.push_back(stoi(s.substr(i)));
return;
}
for(int i=0;i<=9;++i){
s[index]='0'+i;
dfs(end,index+1);
}
}
};
Time complexity O( 1 0 n 10^n 10n)
Spatial complexity O(n)
边栏推荐
- Detailed usage of vim editor
- Introduction to MMS memory optimization of Hisilicon MPP service
- What is thinking
- Sentinel-2 data introduction and download
- Token based authentication
- Three. JS import model demo analysis (with notes)
- Enhanced vegetation index evi, NDVI data, NPP data, GPP data, land use data, vegetation type data, rainfall data
- Difference between thread and task
- Computer network connected but unable to access the Internet
- Overview of common classes
猜你喜欢

Development of video preview for main interface of pupanvr-ui

A complete set of installation procedures (for learning and communication only)

How Bi makes SaaS products have a "sense of security" and "sensitivity" (Part I)

Serial port oscilloscope_ port_ Setup of plotter secondary development environment (including QT setup)

BI 如何让SaaS产品具有 “安全感”和“敏锐感”(上)
![[GIS tutorial] ArcGIS for sunshine analysis (with exercise data download)](/img/60/baebffb2024ddf5f2cb070f222b257.jpg)
[GIS tutorial] ArcGIS for sunshine analysis (with exercise data download)

How to generate provincial data from county-level data in ArcGIS?

MySQL Linux Installation mysql-5.7.24

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

Ten trends of Internet Security in 2022 industry released
随机推荐
Pupanvr- an open source embedded NVR system (1)
Spatial distribution data of national multi-year average precipitation 1951-2021, temperature distribution data, evapotranspiration data, evaporation data, solar radiation data, sunshine data and wind
MySQL Linux Installation mysql-5.7.24
Radiometric calibration and atmospheric correction of sentry 2 L1C multispectral data using sen2cor
Lvgl8.1 hi3536c platform use
1007- stair climbing
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
Qinglong wool - Kaka
Token based authentication
Can‘t find a suitable configuration file in this directory or any parent. Error reporting and resolution
Multi thread learning 4. Sleep, wait, yield, join (), ThreadGroup control the running of threads
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
Some problems of silly girl solved
C asynchronous programming (async and await) and asynchronous method synchronous invocation
Platform of ASoC framework driven by alsa
Chrome is amazingly fast, fixing 40 vulnerabilities in less than 30 days
Applet pull-down load refresh onreachbottom
Longest palindrome string
[GIS tutorial] ArcGIS for sunshine analysis (with exercise data download)
Image processing 13- calculation of integral diagram