当前位置:网站首页>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;
}
};边栏推荐
- Pupanvr hardware and software board side development environment configuration (4)
- How to quickly reference uview UL in uniapp, and introduce and use uviewui in uni app
- Summary of problems in rv1109/rv1126 product development
- 深入理解异步编程
- [cjson] precautions for root node
- Force/release learning and sorting in IC Verification (6) research on the influence of wire type signals
- Three. JS import model demo analysis (with notes)
- [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
- PHP实现图片登录验证码的解决方案
- Some problems of silly girl solved
猜你喜欢

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

The most commonly used objective weighting method -- entropy weight method

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

38. 外观数列

Codis 3. X expansion and contraction

Ecosystem type distribution data, land use data, vegetation type distribution and nature reserve distribution data

Stm32f4 ll library multi-channel ADC

Microsoft announces that it will discontinue support for older versions of visual studio

Save the object in redis, save the bean in redis hash, and attach the bean map interoperation tool class

4.3 模拟浏览器操作和页面等待(显示等待和隐式等待、句柄)
随机推荐
Acquisition of Lai data, NPP data, GPP data and vegetation coverage data
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
JS to determine whether the tags of multiple classes are empty
Link: fatal error lnk1168: cannot open debug/test Solution of exe for writing
Pupanvr- establishment of development environment and diary, addition of some basic tool functions (3)
MySQL5.7.21 Build For ARM
Realease package appears – missing type parameter
Detailed analysis of mathematical modeling problem a (vaccine production scheduling problem) of May Day cup in 2021
Pupanvr create project and management script (2)
深入理解异步编程
Calculation method notes for personal use
Sv806 QT UI development
How to quickly reference uview UL in uniapp, and introduce and use uviewui in uni app
62. the last number left in the circle
Set common methods
How Bi makes SaaS products have a "sense of security" and "sensitivity" (Part I)
4.3 模拟浏览器操作和页面等待(显示等待和隐式等待、句柄)
31. stack push in and pop-up sequence
It costs less than 30 yuan, but we still don't build it quickly - check the small knowledge of software application
Detailed explanation of data envelopment analysis (DEA) (taking the 8th Ningxia provincial competition as an example)