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;
}
};

最新文章

  1. git 高级命令
  2. 【转】利用optimize、存储过程和系统表对mysql数据库表进行批量碎片清理释放表空间
  3. oracle 备份和还原还有创建用户、表空间、授权
  4. php5.5新函数array_column
  5. HashSet 读后感
  6. Linear Regreesion
  7. Solr6.6 Tomcat8部署
  8. 选择排序—简单选择排序(Simple Selection Sort)
  9. Linux 技巧:让进程在后台可靠运行的几种方法【转】
  10. Xshell利用lrzsz工具上传下载
  11. 接口测试之——Charles抓包及常见问题解决(转载自https://www.jianshu.com/p/831c0114179f)
  12. synchronized中判断条件用while而不是if
  13. composer windows安装,使用新手入门
  14. php模板引擎之blade
  15. 结构体变量的sizeof计算
  16. 【动态规划】CDOJ1692 这是一道比CCCC简单题更有想象力的中档题
  17. hdu2647(拓扑排序)
  18. mysql中int(M) tinyint(M)中M的作用
  19. Winform ObservableCollection 添加删除修改无效
  20. Spark Streamming 基本输入流I(-) :File/Hdfs

热门文章

  1. Noip模拟52 2021.9.13
  2. 状压dp学习笔记(紫例题集)
  3. 关于把RTL工程代码封装成IP时对define宏定义参数的处理
  4. JAVA笔记6__抽象类/接口/多态/instanceof关键字、父类设计法则
  5. Java安全之Thymeleaf SSTI分析
  6. 如何将声学的spectrogram(声谱图)重新反变换成时域语音信号
  7. 彻底掌握 Commonjs 和 Es Module
  8. git 回滚版本
  9. Spring 为啥默认把bean设计成单例的?
  10. 菜鸡的Java笔记 简单JAVA 类的开发原则以及具体实现