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 ...
随机推荐
- CentOS 7:快速安装Tomcat7.x
到官网下载对应的压缩包,CentOS 7的Tomcat下载地址:http://tomcat.apache.org/download-70.cgi,下载后传进服务器中并放在你指定的位置上. 或者使用命令 ...
- JavaScript中的this对象指向理解
在JavaScript中,this不是固定不变的,它的指向取决于上下文环境,一般的,认为this指向使用它时所在的对象.主要有以下几类指向: 在方法中,this 表示该方法所属的对象. 如果单独使用, ...
- distinct-subsequences leetcode C++
Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...
- [mysql课程作业]我的大学|作业
第八周周五 1.将xs表中王元的专业改为"智能建筑". # update xs set 专业名='智能建筑' where 姓名='王元'; # select * from xs w ...
- MySQL中特别实用的几种SQL语句送给大家
在写SQL时,经常灵活运用一些SQL语句编写的技巧,可以大大简化程序逻辑.减少程序与数据库的交互次数,有利于数据库高可用性,同时也能显得你的SQL很牛B,让同事们眼前一亮. 目录 实用的SQL 1.插 ...
- k8s入坑之路(2)kubernetes架构详解
每个微服务通过 Docker 进行发布,随着业务的发展,系统中遍布着各种各样的容器.于是,容器的资源调度,部署运行,扩容缩容就是我们要面临的问题. 基于 Kubernetes 作为容器集群的管理平 ...
- GitHub出现Permission denied (publickey)
Permission denied (publickey) 没有权限的publickey 重新生成一次ssh key即可解决 ssh-keygen -t rsa -C "这里输入你的邮箱&q ...
- SpringCloud升级之路2020.0.x版-34.验证重试配置正确性(3)
本系列代码地址:https://github.com/JoJoTec/spring-cloud-parent 我们继续上一节针对我们的重试进行测试 验证针对可重试的方法响应超时异常重试正确 我们可以通 ...
- 【Linux】解压分卷压缩的zip文件
例如linux.zip.001, linux.zip.002, linux.zip.003. 1. cat linux.zip* > linux.zip #合并为一个zip包. 2. unzip ...
- Asp.net core自定义依赖注入容器,替换自带容器
依赖注入 在asp.net core程序中,众所周知,依赖注入基本上贯穿了整个项目,以通用的结构来讲解,控制器层(Controller层)依赖业务层(Service层),业务层依赖于仓储层(Repos ...