LeetCode – Refresh – Count and Say
2015-03-19 07:20
344 查看
Pretty straight forward. count numbers and put char.
class Solution { public: string getNext(string s) { ostringstream oss; char rec = s[0]; int len = s.size(), num = 1; for (int i = 1; i < len; i++) { if (rec != s[i]) { oss << char(num + '0') << rec; rec = s[i]; num = 1; } else num++; } oss << char(num + '0') << rec; return oss.str(); } string countAndSay(int n) { string result = "1"; for (int i = 2; i <= n; i++) { result = getNext(result); } return result; } };
相关文章推荐
- Leetcode:Count and Say
- LeetCode-Count and Say
- LeetCode-Count and Say
- leetcode-38-Count and Say 基础题
- 【leetcode】第38题 Count and Say 题目+解析+代码
- [LeetCode] Count and Say
- 【LeetCode 38_字符串_算术运算】Count and Say
- LeetCode 38 Count and Say
- LeetCode-Count and Say
- leetcode 64: Count and Say
- LeetCode(38) 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
- LeetCode: Count and Say
- leetcode: count and say
- Leetcode-Count and Say-Python