leetcode Count and Say
2015-05-13 15:30
225 查看
代码:
#include<iostream> #include<string> #include<vector> using namespace std; string countAndSay(int n) { string s = "1"; int i = 0; while (--n > 0) { char c = s[0]; string b = ""; i = 0; while (i < s.length()) { i++; int count = 1; while (i<s.length()&&s[i] == c) { count++; i++; } b = b + (char)(count + '0'); b = b + c; if (i == s.length()) { break; } c = s[i]; } s = b; } return s; } int main() { cout << countAndSay(2) << endl; }
相关文章推荐
- LeetCode 038-Count and Say
- Leetcode: Count and Say
- [LeetCode]题解(python):038-Count and Say
- Leetcode: Count and Say
- leetcode第17题----- Count and Say
- 【Leetcode】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
- Count and Say--LeetCode
- LeetCode——Count and Say
- leetcode-38 count and say
- Leetcode: Count and Say
- [LeetCode] Count and Say (使用java string 体会)
- leetcode笔记--Count and Say