44-Count and Say
- Count and Say My Submissions QuestionEditorial Solution
Total Accepted: 79863 Total Submissions: 275285 Difficulty: Easy
The count-and-say sequence is the sequence of integers beginning as follows:
1, 11, 21, 1211, 111221, …
1 is read off as “one 1” or 11.
11 is read off as “two 1s” or 21.
21 is read off as “one 2, then one 1” or 1211.
Given an integer n, generate the nth sequence.
Note: The sequence of integers will be represented as a string.
Submission Details
18 / 18 test cases passed.
Status: Accepted
Runtime: 0 ms
beats:69.03%
思路:看懂题目即可,后一个数由前一个数根据规则生成
class Solution {
public:
string countAndSay(int n) {
vector<char> vec;
int i=2;
string pres("1");
if(n<=1)return pres;
pres="11";
while(i++<n){
int count=1;
string s;
for(int j=0;j<pres.size();++j)
if(pres[j]==pres[j+1]&&count<9)count++;//<9不知会不会出现大于9个一样数的情况
else{
s.push_back(count+'0');
s.push_back(pres[j]);
count=1;
}
pres = s;
}
return pres;
}
};
44-Count and Say的更多相关文章
- Mongodb学习笔记四(Mongodb聚合函数)
第四章 Mongodb聚合函数 插入 测试数据 ;j<;j++){ for(var i=1;i<3;i++){ var person={ Name:"jack"+i, ...
- python学习day4
目录 一.迭代器 二.yield生成器 三.装饰器 四.递归 五.基础算法 迭代器 #1.在不使用for循环的情况下 li = [11 ,22, 33, 44] #count = len(li) #s ...
- python写xml文件
为了便于后续的读取处理,这里就将信息保存在xml文件中,想到得到的文件如下: 1 <?xml version="1.0" encoding="utf-8" ...
- MongoDB学习笔记(四)
第四章 Mongodb聚合函数 插入 测试数据 for(var j=1;j<3;j++){ for(var i=1;i<3;i++){ var person={ Name:"ja ...
- [Swift]LeetCode13. 罗马数字转整数 | Roman to Integer
Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 ...
- [Swift]LeetCode684. 冗余连接 | Redundant Connection
In this problem, a tree is an undirected graph that is connected and has no cycles. The given input ...
- Python开发【第三篇】基本数据类型
整型 int __author__ = 'Tang' # 将字符串转换为数字 a = " b = int(a) # 前面是0的数转换,默认base按照十进制 a = " b = i ...
- TCP连接异常:broken pipe 和EOF
本文介绍3种TCP连接异常的情况. 1.server端没有启动,client尝试连接 ./client dial failed: dial tcp 127.0.0.1:8080: connect: c ...
- zombodb 几个方便的_cat api
zombodb 暴露所有es _cat/ api 为视图,我们可以通过视图方便的查询es 的信息,默认在zdb的schema 中 包含的视图 几个方便的view 查看索引统计信息zdb.index_s ...
- 【ThreadLocal】使用ThreadLocal实现线程安全
非线程安全 public class UnSafeThreadLocalDemo { private int count = 0; public static void main(String[] a ...
随机推荐
- the Agiles Scrum Meeting 1
会议时间:2020.4.9 20:00 1.每个人的工作 今天已完成的工作 前端 学习JavaScript.Vue.ElementUI相关知识 issues:预习任务-前端:JavaScript 预习 ...
- 热身训练2 GCD
题目描述 简要题意: n个数字,a1,a2,...,an m次询问(l,r),每次询问需回答 1.gcd(al,al+1,al+2,...,ar);2.gcd(ax,ax+1,ax+2,...,ay ...
- qgis3.16.6+vs2017再编译(debug+release)
参考 https://www.cnblogs.com/superbi/p/11188145.html 文章以及其它文章,对qggis3.16.6进行了重新编译 一.编译准备 1.Cygwin 1.1安 ...
- 零基础学习Linux必会的60个常用命令
Linux必学的60个命令Linux提供了大量的命令,利用它可以有效地完成大量的工 作,如磁盘操作.文件存取.目录操作.进程管理.文件权限设定等.所以,在Linux系统上工作离不开使用系统提供的命令. ...
- Spring MVC:HandlerMapping
HandlerMapping 的类图 Spring中存在两种类型的handlers.第一种是 handler mappings(处理程序映射).它们的角色定位与前面所描述的功能完全相同.它们尝试将当前 ...
- Verilog设计技巧实例及实现
Verilog设计技巧实例及实现 1 引言 最近在刷HDLBits的过程中学习了一些Verilog的设计技巧,在这里予以整理.部分操作可能降低代码的可读性和Debug的难度,请大家根据实际情况进行使用 ...
- Python ValueError: Attempted relative import in non-package Relative import相对引用 错误
包含相对路径import的python脚本不能直接运行,只能作为module被引用. 例如 from . import mod1 有这样代码的文件只能最为moulule为不能直接运行.相对路径就是相对 ...
- poj 2226 Muddy Fields(最小点覆盖)
题意: M*N的矩阵,每个格不是*就是#. *代表水坑,#代表草地. 农民要每次可以用一块宽为1,长不限的木板去铺这个矩阵.要求这块木板不能覆盖草地.木板可以重复覆盖(即一块木板与另一块木板有 ...
- 地表最强IDE ——Visual Studio 2022正式发布
地表最强IDE--Visual Studio 2022昨天正式发布啦! 堪称宇宙第一IDE工具集的Visual Studio,在经过不断更新优化之后,新版本就要与大家见面了.本次新版本发布,有许多令人 ...
- JavaScript 事件循环
JavaScript 事件循环 事件循环 任务队列 async/await 又是如何处理的呢 ? 定时器问题 阻塞还是非阻塞 实际应用案例 拆分 CPU 过载任务 进度指示 在事件之后做一些事情 事件 ...