leetcode - Count and Say
2013-03-28 10:52
316 查看
题目描述:点击此处
class Solution { public: string genNext(string cur){ string rlt = ""; char t[20]; int length = cur.length(); int i = 0; char c = cur.at(0); int len = 0; while(i<length){ while (i<length && cur.at(i)==c){ len++; i++; } sprintf(t, "%d%c", len, c); rlt += t; len =0; if (i<length){ c = cur.at(i); } } return rlt; } string countAndSay(int n) { // Start typing your C/C++ solution below // DO NOT write int main() function string rlt = "1"; while (--n > 0){ rlt = genNext(rlt); } return rlt; } };
相关文章推荐
- [leetcode]Count and Say
- [C++]LeetCode: 20 Count and Say
- (leetCode)Count and Say --- 统计读
- 【LeetCode】38 - Count and Say
- leetcode 题解 || Count and Say 问题
- Leetcode: Count and Say
- 【leetcode】Count and Say
- 【leetcode】Count and Say (easy)
- leetcode-38 Count And Say
- [LeetCode] Count and Say
- [Leetcode]38--Count and Say
- Count and Say --leetcode
- 开始刷leetcode day30:Count and Say
- LeetCode-Count and Say
- Leetcode38:count and say数一数,说一说
- [LeetCode]Count and Say
- [Leetcode]#38 Count and Say
- LeetCode-Count and Say
- leetcode 038 Count and Say
- leetcode-38-Count and Say 基础题