当前位置:网站首页>38. appearance series
38. appearance series
2022-06-12 05:25:00 【anieoo】
Original link :38. Look-and-say sequence
solution:
Double pointer
① Default string from state "1" Start , Since the state has been defined "1", Just loop n-1 Secondary steps ②
② Given a string , Enumerate each character j,k from j Start , Find the characters j The continuous interval of [j,k - 1], Number and character j Joining together to t After the string ,j Continue from k Position start enumeration
③ Every time ② Update after operation res
class Solution {
public:
string countAndSay(int n) {
string res = "1"; // Define the first item in the sequence
for(int i = 0;i < n - 1;i++) {
string t;
for(int j = 0;j < res.size();) {
int k = j + 1;
while(k < res.size() && res[k] == res[j]) k++;
t += to_string(k - j) + res[j];
j = k;
}
res = t;
}
return res;
}
};边栏推荐
- Surface net radiation flux data, solar radiation data, rainfall data, air temperature data, sunshine duration, water vapor pressure distribution, wind speed and direction data, surface temperature
- JS controls the display and hiding of tags through class
- Performance & interface test tool - JMeter
- The way to promote software test engineer
- Servlet core technology
- Multi thread learning v. volatile visibility and cache inconsistency, instruction reordering
- Multi thread learning 4. Sleep, wait, yield, join (), ThreadGroup control the running of threads
- Test work summary - performance test indicators
- Pupanvr hardware and software board side development environment configuration (4)
- Chapter 1
猜你喜欢

Yolo opencv scale identification scale reading identification water gauge identification water level identification source code

Detailed usage of vim editor

Chrome is amazingly fast, fixing 40 vulnerabilities in less than 30 days

It costs less than 30 yuan, but we still don't build it quickly - check the small knowledge of software application

Introduction to audio alsa architecture

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

Detailed tutorial on the use of yolov5 and training your own dataset with yolov5

Introduction to MMS memory optimization of Hisilicon MPP service

Codis 3. X expansion and contraction

Automated test - dark horse headline test project
随机推荐
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
Index fund summary
Qs100 at command mqtt access thingsboard
什么是工程预付款
Transpiration and evapotranspiration (ET) data, potential evapotranspiration, actual evapotranspiration data, temperature data, rainfall data
National land use data of 30m precision secondary classification
Applet pull-down load refresh onreachbottom
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
59 - II. Maximum value of the queue
Performance & interface test tool - JMeter
Project requirements specification
MySQL5.7.21 Build For ARM
One dragon and one knight accompanying programmers are 36 years old
Pytorch was reported by a large number of netizens that torchrec, a new library, was "born" and has a large scale
How to clear floating, and how does it work?
Platform of ASoC framework driven by alsa
Uview customer management JS
Yolov5 realizes road crack detection
2022 "college entrance examination memory" has been packaged, please check!
Matlab: halftone and dither conversion