[leetcode]38. Count and Say
来源:互联网 发布:淘宝网保安服装 编辑:程序博客网 时间:2024/06/01 10:23
题目链接:https://leetcode.com/problems/count-and-say/
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.
class Solution {public: string countAndSay(int n) { string currRes=""; if(n<=0) return currRes; string preRes="1"; if(n==1) return preRes; for(int i=1;i<n;i++) { char tmp=preRes[0]; int times=1; for(int j=1;j<preRes.size();j++) { if(preRes[j]==tmp) times++; else { currRes+=to_string(times); currRes.push_back(tmp); tmp=preRes[j]; times=1; } } currRes+=to_string(times); currRes.push_back(tmp); preRes=currRes; currRes=""; } return preRes; }};
0 0
- [LeetCode]38.Count and Say
- LeetCode --- 38. Count and Say
- LeetCode 38.Count and Say
- [Leetcode] 38. Count and Say
- 38. Count and Say LeetCode
- 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
- 2016年11月9日学习总结
- 基于MVC模式的MVC 5框架
- WS查询手机号信息
- CF625D-Finals in arithmetic-构造
- canvas画奥运五环
- [leetcode]38. Count and Say
- 我的一下步
- 【C语言】模拟用户登录系统 以及演示多个字符从两端向中间靠拢
- 装配Bean(五)
- hdu1176 免费馅饼 动态规划 二维数组实现
- 连连看(广搜)
- 什么是iNAND,iNAND有什么优点
- 利用SimpleTagSupport接口自定义标签
- scala 类定义构造函数与继承