[Leetcode] 38 - Count and Say
2015-01-29 17:18
357 查看
原题链接:https://oj.leetcode.com/problems/count-and-say/
这道题其实考的还是细心了,外层循环n,内存循环当前字符长度。
这道题其实考的还是细心了,外层循环n,内存循环当前字符长度。
class Solution { public: string countAndSay(int n) { string res = ""; if (n < 0) return res; res = "1"; int i = 1; while (i < n) { string temp = ""; char prev = '-'; int count = 0; for (int j = 0; j < res.size(); ++j) { if (prev != res[j]) { if (prev != '-') { temp.push_back('0' + count); temp.push_back(prev); } prev = res[j]; count = 1; } else { ++count; } } temp.push_back('0' + count); temp.push_back(prev); ++i; res = temp; } return res; } };
相关文章推荐
- 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
- LeetCode 38 : Count and Say (Java)
- 【LeetCode 38】Count and Say(Python)