当前位置:网站首页>leetcode.38 ---外观数列
leetcode.38 ---外观数列
2022-06-10 06:46:00 【_End丶断弦】
外观数列

题解:
动图演示:
代码如下:
class Solution {
public:
string countAndSay(int n) {
string res = "1";
if(n == 1) return res;//n=1直接返回
for(int i = 1;i < n;i++){
string tmp;
int l = 0, r = 0;//双指针找重复元素
while(r < res.size()){
while(r < res.size() && res[r] == res[l]) r++;//相等r就一直往右走
tmp += to_string(r - l) + res[l]; //拼接起来
l = r;//更新l到r的位置
}
res = tmp;
}
return res;
}
};
时间复杂度:O(n^2)
空间复杂度;O(1)
边栏推荐
- pyinstaller
- CMD of Jerry's AI protocol_ SET_ BT_ Addr [chapter]
- scala fastjson 获取jsonArray中 某个key的最大值
- Principe de l'algorithme d'extraction de l'ensemble d'éléments fréquents associés à l'alarme dans le cadre de l'exploitation et de l'entretien intelligents
- Baidu cloud address identification
- Teacher lihongyi's notes on machine learning -4.1 self attention
- 判斷進程是否有管理員權限
- Tensorflow experiment 10 - image flipping and zooming
- Business topic: user growth analysis
- Common skills of JS code
猜你喜欢

Teacher lihongyi's notes on machine learning -5 transformer

Rsync+inotify remote synchronization

Why can't lldb print view bounds? - Why can't LLDB print view. bounds?

C Advanced (feature)

QT upper computer controls ABB in real time through EGM

Qt--- create dialog box 3: implementation of shape variable dialog box

解析:稳定币不是“稳定的币”,其本质是一种产品

Go zero micro Service Practice Series (II. Service splitting)

3DMAX modeling scenario

告警消息何去何从?在飞书中飞起来
随机推荐
Unlock TRPC high performance password: introduction to network scheme!
成功解决:ImportError: cannot import name ‘Imputer‘ from ‘sklearn.preprocessing
最长公共子序列
解锁 tRPC 高性能密码:网络方案简介!
618. How to prepare for the great promotion
Leetcode第 79 场双周赛-完成所有题目
解析:稳定币不是“稳定的币”,其本质是一种产品
Business topic: user usage path analysis
在 Kubernetes 中基于 StatefulSet 部署 MySQL(上)
tensorflow实验十-----图片翻转与缩放
Getting started with pytorch: training a deep neural network (DNN)
Leetcode-473. 火柴拼正方形:一个4X15的皇后问题(其实就是一个回溯法)
Dream notes 0610
TAP 系列文章 2 | Tanzu Application Platform v1.1 安装配置步骤
YTU——C语言习题 折半查找
Qt--- create dialog box 3: implementation of shape variable dialog box
想要粽子可以,但是得经过我的认证授权才可以
ROS2+Gazebo11+Car+OpenCV巡线识别和速度转向控制学习
JS数据交互之本地存储
YoseZang 原创 特征码定位器 SignatureTest V6.36 Rls 发布

