当前位置:网站首页>leetcode. 38 --- appearance series
leetcode. 38 --- appearance series
2022-06-10 06:57:00 【_ End, broken chord】
Look-and-say sequence

Answer key :
Dynamic diagram demonstration :
The code is as follows :
class Solution {
public:
string countAndSay(int n) {
string res = "1";
if(n == 1) return res;//n=1 Go straight back to
for(int i = 1;i < n;i++){
string tmp;
int l = 0, r = 0;// Double pointer to find duplicate elements
while(r < res.size()){
while(r < res.size() && res[r] == res[l]) r++;// equal r Just keep going right
tmp += to_string(r - l) + res[l]; // Splice up
l = r;// to update l To r The location of
}
res = tmp;
}
return res;
}
};
Time complexity :O(n^2)
Spatial complexity ;O(1)
边栏推荐
- Arduino配置ESP32开发环境
- 29. solution for 300ms delay time of click event at mobile terminal
- pyinstaller
- 2022-2027 (New Edition) report on the prospect and future development of China's property rights trading industry
- PHP implementation keeps two decimal places
- 【计量经济学】工具变量估计与两阶段最小二乘法
- ShardingSphere实践(6)——弹性伸缩
- Loj10131. "all in one" 4.4 example 2 "dark chain problem solving tree difference (edge difference)
- QT---创建对话框3:形状可变对话框的实现
- 成功解决:ImportError: cannot import name ‘Imputer‘ from ‘sklearn.preprocessing
猜你喜欢

微信团队分享:微信后台在海量并发请求下是如何做到不崩溃的

Nignx configuring websocket

3DMAX modeling scenario

想要粽子可以,但是得经过我的认证授权才可以

pyinstaller

一举刷新 54 个中文 NLP 任务基准,ERNIE3.0加持下的EasyDL可能是市面上最好用的NLP开发平台...

ShardingSphere实践(6)——弹性伸缩

618 大促来袭,浅谈如何做好大促备战

Embedded development | common operations of EEPROM driver code

Deploy MySQL based on statefulset in kubernetes (Part 1)
随机推荐
TeleyeControlor V8.47版本发布 更改Socket框架
All in one 1281 Dynamic programming of the longest ascending subsequence solution
Cannot open 'appears when Proteus simulates p * * * \lisa5476 Error in SDF '
618. How to prepare for the great promotion
智能合并视频,随机合并视频封面,并预设新标题
Arduino配置ESP32开发环境
Teleyecontroller v8.16 release complete registry function
Beyond compare
tensorflow实验九----------泰坦尼克号
Print linked list from end to end of sword finger offer
解决:vscode中go语言项目不能自动导包问题
【宽度优先搜索】LeetCode1091二进制矩阵中的最短路径
Scala fastjson gets the maximum value of a key in the jsonarray
Successfully solved: importerror: cannot import name 'import' from 'sklearn preprocessing
3DMAX modeling scenario
2022-2027 (New Edition) report on the prospect and future development of China's property rights trading industry
原博客的地址
白加黑过360启动项工具源码发布 多文件过启动项代码
tensorflow实验十-----图片翻转与缩放
刘勇智:一码通缺陷分析与架构设计方案丨声网开发者创业讲堂 Vol.02

