[LeetCode] Count and Say
2013-01-28 04:38
351 查看
class Solution { public: string countAndSay(int n) { // Start typing your C/C++ solution below // DO NOT write int main() function vector<int> v; vector<int> t; v.push_back(1); for (int i = 1; i < n; i++) { t.clear(); for (int pos = 0; pos < v.size(); pos++) { int count = 1; while (pos + 1 < v.size() && v[pos] == v[pos + 1]) { count++; pos++; } t.push_back(count); t.push_back(v[pos]); } v = t; } string ret = ""; for (int i = 0; i < v.size(); i++) ret += v[i] + '0'; return ret; } };
Small Case: 8ms
Large Case: 8ms
相关文章推荐
- Leetcode NO.38 Count and Say
- leetcode - Count and Say
- 【LeetCode】Count and Say
- leetcode笔记--Count and Say
- Leetcode:Count and Say
- 【LeetCode38】【Count and Say】StringBuilder
- leetcode解题方案--038--count and say
- 【LeetCode】Count and Say 解题报告
- LeetCode Count and Say
- LeetCode 038 Count and Say
- Leetcode || Count and Say
- leetcode ——Count and Say
- LeetCode刷题笔录Count and Say
- Leetcode Count and Say 数数列数字
- [leetcode]Count and Say (伯爵说 C语言实现)
- LeetCode 38 Count and Say
- leetcode38---Count and Say
- [LeetCode][Java] Count and Say
- [Leetcode] Count and Say
- leetcode(38) - Count and Say