# LeetCode之Count and Say

/*这是一道模拟题。第n个序列是根据n-1个序列获得的，所以

class Solution {
public:
string countAndSay(int n) {
string res("1");
while(--n) res = getNext(res);
return res;
}

string getNext(string &s){
string res("");
for(int i = 0; i < s.size();){
int j = i + 1;
for(; j < s.size(); ++j){
if(s[j] != s[i]) break;
}
res += num2string(j-i) + s[i];
i = j;
}
return res;
}

string num2string(int num){
string res("");
while(num > 0){
char c = '0' + num%10;
res += c;
num /= 10;
}
reverse(res.begin(), res.end());
return res;
}
};

• 本文已收录于以下专栏：

## LeetCode Count and say

The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 11122...

## 【leetcode c++】38 Count and Say

Count and Say The count-and-say sequence is the sequenceof integers beginning as follows: 1, 11, 2...
• hqq39
• 2015年06月26日 22:40
• 384

## Leetcode - 38. Count and Say

38. Count and Say题目简介 The count-and-say sequence is the sequence of integers beginning as follows:...

## leetcode 题解 || Count and Say 问题

problem： The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 2...

## LeetCode算法题之Count and Say

//问题描述 The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 121...

## <leetcode系列> Count And Say

The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221...

举报原因： 您举报文章：LeetCode之Count and Say 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)