LeetCode(38)--Count and Say
来源:互联网 发布:软件项目总结ppt 编辑:程序博客网 时间:2024/06/03 07:32
第n个字符串依赖于第n-1个字符串,从左往右依次数出有连续几个数字。举例如下:
1
11 上个字符串中有1个1
21 上个字符串中有2个1
1211上个字符串中有1个2、1个1
111221
312211上个字符串中有3个1、2个2、1个1
13112221
1113213211
实现代码如下:
class Solution {public: string countAndSay(int n) { string s="1"; for(int i=1;i<n;i++) { string temp=""; int count=1; for(int j=0;j<s.size();j++) { while(j<s.size()-1&&s[j]==s[j+1]) { count++; j++; } temp=temp+(char)(count+'0')+s[j]; count=1; } s=temp; } return s; }};
阅读全文
0 0
- [LeetCode 38] Count and Say
- LeetCode(38) Count and Say
- [leetcode 38] Count and Say
- [Leetcode] 38 - Count and Say
- leetcode-38 count and say
- [LeetCode 38]Count and Say
- LeetCode 38 Count and Say
- leetcode-38 Count and Say
- Leetcode 38 Count and Say
- Leetcode---(38)Count and Say
- leetcode 38: Count and Say
- Leetcode# 38 Count and Say
- leetcode[38]:Count and Say
- leetcode-38 Count And Say
- [Leetcode]#38 Count and Say
- LeetCode 38 Count and Say
- leetcode 38:Count and Say
- [LeetCode-38] Count and Say
- requests库入门-11-自定义请求
- 判断字符数组中是否所有的字符只出现了一次(左程云)非递归堆排序实现
- UGUI 学习笔记 2 静态字体
- poj 3616 Milking Time
- 软件测试——测试流程重要性
- LeetCode(38)--Count and Say
- hibernate_事务处理、session管理
- C# 后台分页
- 两分钟理解Android中PX、DP、SP的区别
- class类命名
- (1)自动化selenium准备与元素定位代码
- 2512: 小明的惩罚
- 弱类型语言 Hash比较存在缺陷
- 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树。