# 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.

Solution:

class Solution {
public:
string countAndSay(int n) {
if(n == 0) return "";
string current = "1";
string next = "";
stringstream stream;
while(--n)
{
int count = 1;
current += '-';
for(int i = 1; i < current.length(); ++i)
{
if(current[i] == current[i-1]) count++;
else
{
string tmp;
stream << count;
stream >> tmp;
next += tmp + current[i-1];
stream.clear();
count = 1;
}
}
current = next;
next.clear();
}

return current;
}
};

#### leetCode 38.Count and Say (计数和发言) 解题思路和方法

2015-07-09 20:40:16

#### Count and Say @python 题解

2015-04-23 10:03:06

#### LeetCode Count and Say 解题报告

2014-12-05 15:09:28

#### leetcode -- Count and Say -- 理解题意

2015-12-09 11:45:44

#### LeetCode（38） Count and Say

2015-08-26 11:14:38

#### [LeetCode] 038. Count and Say (Easy) (C++/Python)

2015-07-30 10:04:05

#### LeetCode 38 : Count and Say (Java)

2015-12-02 22:50:52

#### LeetCode38 Count and Say(C语言解决)

2016-11-15 12:13:21

#### LeetCode 38 Count and Say(C,C++,Java,Python)

2015-05-19 21:36:24