1. 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的更多相关文章

  1. Mongodb学习笔记四(Mongodb聚合函数)

    第四章 Mongodb聚合函数 插入 测试数据 ;j<;j++){ for(var i=1;i<3;i++){ var person={ Name:"jack"+i, ...

  2. python学习day4

    目录 一.迭代器 二.yield生成器 三.装饰器 四.递归 五.基础算法 迭代器 #1.在不使用for循环的情况下 li = [11 ,22, 33, 44] #count = len(li) #s ...

  3. python写xml文件

    为了便于后续的读取处理,这里就将信息保存在xml文件中,想到得到的文件如下: 1 <?xml version="1.0" encoding="utf-8" ...

  4. MongoDB学习笔记(四)

    第四章 Mongodb聚合函数 插入 测试数据 for(var j=1;j<3;j++){ for(var i=1;i<3;i++){ var person={ Name:"ja ...

  5. [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 ...

  6. [Swift]LeetCode684. 冗余连接 | Redundant Connection

    In this problem, a tree is an undirected graph that is connected and has no cycles. The given input ...

  7. Python开发【第三篇】基本数据类型

    整型 int __author__ = 'Tang' # 将字符串转换为数字 a = " b = int(a) # 前面是0的数转换,默认base按照十进制 a = " b = i ...

  8. TCP连接异常:broken pipe 和EOF

    本文介绍3种TCP连接异常的情况. 1.server端没有启动,client尝试连接 ./client dial failed: dial tcp 127.0.0.1:8080: connect: c ...

  9. zombodb 几个方便的_cat api

    zombodb 暴露所有es _cat/ api 为视图,我们可以通过视图方便的查询es 的信息,默认在zdb的schema 中 包含的视图 几个方便的view 查看索引统计信息zdb.index_s ...

  10. 【ThreadLocal】使用ThreadLocal实现线程安全

    非线程安全 public class UnSafeThreadLocalDemo { private int count = 0; public static void main(String[] a ...

随机推荐

  1. alertmanager的使用

    alertmanager的使用 一.Alertanager的安装 1.下载 2.安装 3.启动 4.alertmanager和prometheus的整合 二.告警分组 1.告警规则 2.alertma ...

  2. Noip模拟17 2021.7.16

    我愿称这场考试为STL专练 T1 世界线 巧妙使用$bitset$当作vis数组使用,内存不会炸,操作还方便,的确是极好的. 但是这个题如果不开一半的$bitset$是会炸内存的,因为他能开得很大,但 ...

  3. 矩形覆盖 牛客网 剑指Offer

    矩形覆盖 牛客网 剑指Offer 题目描述 我们可以用21的小矩形横着或者竖着去覆盖更大的矩形.请问用n个21的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法? class Solution: ...

  4. longest-consecutive-sequence leetcode C++

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...

  5. SpringCloud微服务实战——搭建企业级开发框架(十二):OpenFeign+Ribbon实现负载均衡

      Ribbon是Netflix下的负载均衡项目,它主要实现中间层应用程序的负载均衡.为Ribbon配置服务提供者地址列表后,Ribbon就会基于某种负载均衡算法,自动帮助服务调用者去请求.Ribbo ...

  6. Mysql多实例搭建部署

    [部署背景] 公司测试环境需求多个数据库实例,但是只分配一台MySQL机器,所以进行多实例部署. [部署搭建] 创建软件包路径   mkdir /data/soft/package      /dat ...

  7. prometheus(5)之consul服务自动发现及pushgetway

    pushgetway(push上传metric数据) Pushgateway简介 Pushgateway是prometheus的一个组件,prometheus server默认是通过exporter主 ...

  8. 安装spark 后 NoClassDefFoundError

    安装spark后,hive报 java.lang.NoClassDefFoundError: org/apache/hadoop/mapreduce/InputFormat trace 看是sqoop ...

  9. 旧电脑做服务器--第一篇 sql server 服务器搭建

    背景:旧电脑为2015年的老电脑,联系G50系列,目前键盘鼠标操作都有问题,键盘按键和鼠标左键莫名奇妙变成右击,屏幕显示也是大颗粒.但是配置还可以,16GB内存+256GB三星固态硬盘.所以想搭建作为 ...

  10. Part 23 to 26 Routing in Angular

    Part 23 AngularJS routing tutorial In general, as the application becomes complex you will have more ...