当前位置:网站首页>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;
}
};边栏推荐
- Detailed tutorial on the use of yolov5 and training your own dataset with yolov5
- How Bi makes SaaS products have a "sense of security" and "sensitivity" (Part I)
- 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
- Detailed analysis of mathematical modeling problem a (vaccine production scheduling problem) of May Day cup in 2021
- Alsa architecture application aplay and amixer call relationship (from application layer to kernel driver)
- 深入理解异步编程
- How to deploy dolphin scheduler Apache dolphin scheduler 1.2.0 in cdh5.16.2
- 38. arrangement of strings
- Matlab: halftone and dither conversion
- Pupanvr hardware and software board side development environment configuration (4)
猜你喜欢
![[getting to the bottom] five minutes to understand the combination evaluation model - fuzzy borde (taking the C question of the 2021 college students' numerical simulation national competition as an e](/img/2e/97310ec36aeb1fc1e9c82361141a36.jpg)
[getting to the bottom] five minutes to understand the combination evaluation model - fuzzy borde (taking the C question of the 2021 college students' numerical simulation national competition as an e

Enhanced vegetation index evi, NDVI data, NPP data, GPP data, land use data, vegetation type data, rainfall data

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

Servlet core

Matlab: image rotation and interpolation and comparison of MSE before and after

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

Matlab: halftone and dither conversion

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

Detailed analysis of the 2021 central China Cup Title A (color selection of mosaic tiles)

Pupanvr- an open source embedded NVR system (1)
随机推荐
Qs100 at command mqtt access thingsboard
Test work summary - performance test related issues
JS to determine whether the tags of multiple classes are empty
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
How to quickly reference uview UL in uniapp, and introduce and use uviewui in uni app
Can‘t find a suitable configuration file in this directory or any parent. Error reporting and resolution
The server time zone value ‘Ö Ð¹ ú±ê ×¼ ʱ ¼ ä‘ is unrecognized or represents more than one time zone. You
[getting to the bottom] five minutes to understand the combination evaluation model - fuzzy borde (taking the C question of the 2021 college students' numerical simulation national competition as an e
IC验证中的force/release 学习整理(5)研究对 reg类型信号的影响
Main business objects of pupanvr record (5)
Necessary for Test Engineer -- package capturing tool fiddler
43. Number of occurrences of 1 in 1 ~ n integers
国企为什么要上市
week7
59 - II. Maximum value of the queue
31. stack push in and pop-up sequence
Some optimization methods for UI Application of Qt5 on Hisilicon security platform
Introduction to audio alsa architecture
New knowledge today
Servlet core technology