[leetcode]Count and Say

按照说明模拟。。。

stringstream挺好用的

class Solution {
public:
    string count(const string& now) {
        stringstream ss;
        int i = 0;
        int size = now.size();
        int prev = -1;
        while(i < size) {
           while(i + 1< size && now[i] == now[i + 1]) i++;
           ss << (i - prev) << now[i];
           prev = i;
           i++;
        }
        return ss.str();
    }
    string countAndSay(int n) {
        string now = "1";
        for(int i = 1 ; i < n  ; i++) {
            now = count(now);
        }
        return now;
    }
};
原文地址:https://www.cnblogs.com/x1957/p/3512994.html