标签:表示 char 迭代 style int 题意 cti const 意思
class Solution { public: string countAndSay(int n) { if(n == 0)return string(""); string res("1"); for(int i = 1; i < n; i++) { res = build(res); } return res; } string build(const string& res) { string ret; int len = res.size(); for(int i = 0; i < len; i++) { int count = 1; char x = res[i]; while(i < len && res[i+1]==x) { count++; i++; } ret.push_back(count+‘0‘); ret.push_back(x); } return ret; } };
标签:表示 char 迭代 style int 题意 cti const 意思
原文地址:http://www.cnblogs.com/Kobe10/p/6351638.html